CT37992

The Frugal Pairs Beneath Hammerfall

MediumL5 · Recursion RenegadeAcceptance: 0.0%XP: 60

Hope inherited the counting house at the anvil district of Hammerfall along with its curious bookkeeping system for panels. Time to make sense of it. Task: Print the number of index pairs (i,j), i<j, with a[i]+a[j] <= k. Input format: First line: n and k. Second line: n integers. Output format: Print the pair count (fits 64-bit). Constraints: 2 <= n <= 3287; 0 <= a[i],k <= 1000000000.

Example 1:

Input: 1512 1448018135 743956773 141042609 253613084 714284384 954089544 237234242 329807184 495618064 161459325 247107906 470775651 568716886 253082190 525986530 884844485 765759269 777719856 190215212 103998279 816881658 960937159 353322087 956971721 904254763 909861160 111754291 619365351 270387456 309333294 312932096 285775827 467543726 732993946 689045547 277227073 105386109 66740535 954930884 281256799 386098000 221592633 525838095 834004816 734092639 931584098 176119152 836028884 69904124 694139700 261837271 510244924 459810680 828050861 933446085 802185010 808685535 976375867 688769505 237086809 914095393 144060092 339438985 842956407 329542212 781239057 997139258 330702823 402480157 264954169 650688731 302562713 686620085 336644078 366644812 589737256 350712392 564514748 906092125 866002…
Output: 988266

Example 2:

Input: 234 377947736 68359733 839184976 535348488 462106888 885661487 236742678 484689361 336236321 52732211 646820622 694710732 653068184 999533197 315006947 763112311 162189156 735581546 222140958 599499587 150190216 432644736 896350909 733348388 147587773 916583665 220075331 83965694 419800956 478983642 546131559 661283648 315375221 851833517 912686803 490988197 615332657 559031024 880898414 654569331 855442560 325229774 207939081 227078661 102448519 287759215 754888670 287501137 842337804 603337112 134816277 103687571 484039709 991957103 858375893 435593941 142244820 772909100 926861180 967750283 107923449 854360528 50252247 646350199 862652092 123092500 237973386 171572375 649926300 580066891 139123235 992596711 671716685 208603955 963851875 90098442 473470896 628867688 806076861 774625848 7…
Output: 2067

Example 3:

Input: 3074 1314138289 163700050 991598498 436587857 635452562 216573182 970411528 510860318 594567275 9490734 331156978 508327622 515748734 170718858 372577446 2206462 367073456 632014769 336598783 183776486 605794528 646743441 31731445 493958436 488538856 190053404 708094730 6181028 223994456 776159736 892045437 209686958 928873588 415392050 310896019 890394043 704687932 278629848 356879829 220883811 72828898 709110508 4774464 223221194 817801742 803830384 519896888 610023297 629382055 581145180 341458993 164799084 858093566 980552492 20327201 650745282 446941458 273699731 682678625 419395083 975142237 693435504 226675104 902078758 492963229 715942043 553490859 490159777 882621204 339921280 136923908 429550318 708202752 53167684 422811623 565477491 525704504 253161094 906596854 250766438 269448…
Output: 3603010

Constraints:

2 <= n <= 3287; 0 <= a[i],k <= 1000000000.

Loading...
Test Cases:No test cases
No test cases available.
The Frugal Pairs Beneath Hammerfall - MEDIUM Coding Problem | CodeTikki