CT32149

Theo's Frugal Pairs Ledger

MediumL4 · Loop LordAcceptance: 0.0%XP: 35

Theo the log keeper watches over the clockwork quarter of Gearford's stores of windows. A careful computation stands between order and chaos. 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 <= 2197; 0 <= a[i],k <= 1000000.

Example 1:

Input: 318 1016931 385462 521847 468928 984190 373862 583407 253904 58231 229733 61556 388668 244193 828427 761933 981728 499368 914545 119136 58226 709762 448154 361050 543853 932728 480816 287084 499585 160455 535276 300185 685193 99989 906357 775227 973453 911990 155042 918830 222395 770284 888753 45511 584680 373159 890967 722196 739863 978293 255014 561036 436431 420534 98365 672527 344419 430818 180566 654948 280775 799343 877126 936592 943263 658852 586334 35929 631922 511523 364528 728474 213958 602183 575760 483268 727375 840442 759108 356326 90285 529428 961689 239494 686561 256045 340048 391094 411363 285657 141364 141248 239055 564050 300686 258075 680838 964942 799824 847626 533786 881940 774113 492211 679531 12306 936355 767525 446053 255069 526715 23247 150951 999343 290972 778002 …
Output: 24693

Example 2:

Input: 203 1422142 632390 659058 828423 899119 238099 711188 19252 252064 626035 120822 136841 721324 203823 670573 540780 492792 76340 35049 170851 794 36089 100732 943397 357151 433143 775010 976030 825475 416978 179820 435570 941842 362843 956505 546747 876547 859172 187708 325646 326007 23046 357689 806692 293194 654878 662472 253760 720936 13698 971193 465538 552675 644408 402843 777778 264091 276429 286477 111984 738635 56676 54018 558977 249355 695948 493916 384683 999901 157045 489397 672601 859715 704983 927319 566568 402503 268253 724809 999743 554676 502608 428937 367956 254946 894356 53134 230955 216601 473623 136793 377828 110474 71304 524910 215901 86816 823986 63804 370504 302145 567962 931614 927008 683743 769275 879226 24912 22279 121261 837270 636725 375957 970411 865769 893718 …
Output: 17263

Example 3:

Input: 1785 917027 611279 806855 923459 420920 905355 171298 102999 227963 282970 99417 531830 415046 686683 280439 662393 853641 915466 103976 559516 925163 775712 126948 293930 101392 2873 890547 470757 186774 491282 408688 955521 483094 859008 302508 786284 826205 472436 128946 441620 583067 247235 765586 139171 594735 253286 631957 202113 321421 486351 584752 947294 446177 635720 639453 987520 652607 864822 18900 9868 500736 122057 319042 22083 589122 668542 436977 530528 995112 365193 620719 50215 314315 166915 877730 358042 202997 719222 676423 762709 535298 382086 879375 101068 677013 962303 415479 400360 902073 832416 52818 489689 900160 318510 390744 990616 29930 270893 517191 35633 806238 855580 835601 631698 318458 977701 682194 792454 858961 930446 158961 298190 546626 165525 44171 96…
Output: 637594

Constraints:

2 <= n <= 2197; 0 <= a[i],k <= 1000000.

Loading...
Test Cases:No test cases
No test cases available.
Theo's Frugal Pairs Ledger - MEDIUM Coding Problem | CodeTikki