CT40862

Jatin Counts the scrolls

MediumL5 · Recursion RenegadeAcceptance: 0.0%XP: 60

The ledger master Jatin has been asked to secure the caravan contract. On the desk lies a long table of scrolls readings. 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 <= 2590; -1000000 <= a[i],k <= 1000000.

Example 1:

Input: 1662 1571096 -295687 -375798 118986 322332 -736094 -483370 688946 -447233 -771638 -712864 732161 -582995 412838 -64198 213698 312174 -602198 -374289 679609 -180282 607774 278615 220756 822948 -141152 970639 304327 -768834 -888714 567753 -635904 201367 106479 798934 863026 179674 810031 -503476 187118 -210637 933237 -920086 551747 253655 -771742 474204 204692 -826340 396533 -185111 -530212 626953 -690733 947034 -621413 -549357 -324112 606879 -263079 964811 807227 -545966 -480883 -609889 -161335 -726446 418743 -316817 709199 -923863 277045 -480706 702460 101137 -660725 -577456 365727 -70704 855836 914240 -288774 443474 225877 -723192 721315 -763875 -808768 38142 -136576 589341 -134205 861046 272260 944813 625010 -532084 839072 359552 -286622 803310 493509 -560627 -524509 -355986 254576 71297…
Output: 1344179

Example 2:

Input: 406 -274008 375349 -955243 70489 -854265 -633880 895829 -471505 -394414 366 -974585 -333497 21550 -14198 66364 620730 823721 -21158 320754 -253950 -714877 594435 873808 245743 970772 738682 388326 -850583 -269710 -225457 -646252 303317 644662 618503 794707 -727940 -531133 -150188 405199 -251860 -460330 152048 -199133 8678 -141704 -553896 555618 535636 -204187 577071 -956028 -125357 768949 760122 685976 444854 -206513 -301166 -977643 419366 -894322 765768 612210 -979870 261075 995297 -497614 -963642 555610 438714 265823 -74982 728330 -586045 -453262 -153427 -862706 -974679 -39935 1213 897452 99771 925494 -766043 -680956 913748 584056 -451606 -961349 -124569 772068 856962 284204 -715745 52024 -43287 505030 667324 403097 235245 -510596 -202469 -628744 467392 805172 683098 -198378 -39787 -4456…
Output: 27971

Example 3:

Input: 2139 1440704 -468757 -526484 -842705 -421197 188778 398789 -894640 663722 -68593 -219259 641103 451785 608767 -483832 -269947 -135585 85526 220810 622459 912977 684090 -981435 98964 -809922 595392 396975 -43116 -530713 147358 -673852 -693459 -802257 -648836 -414719 669436 186678 296778 220063 -153579 902160 352261 -318101 -401672 754913 -492987 -715667 -326124 574810 -639185 323444 -511752 -440413 -82289 876744 97396 -452681 -876900 -508688 -360219 -558512 145852 -225932 -241776 -44169 -334511 -121921 -195509 363832 569258 -428954 980706 -185984 -348513 445825 -372422 -912172 -508848 -757817 179344 867303 -45776 251950 791040 -954723 780056 -362582 -29855 948367 -490705 702596 -780408 -581455 529546 978976 211227 -99488 -907651 922308 -810486 924503 488554 -357825 -364467 980862 435213 -12…
Output: 2193104

Constraints:

2 <= n <= 2590; -1000000 <= a[i],k <= 1000000.

Loading...
Test Cases:No test cases
No test cases available.