CT30345

Tara and the Frugal Pairs

MediumL4 · Loop LordAcceptance: 0.0%XP: 35

Caravans arrive at the smokehouses of Brineport with crates of segments, and Tara the accountant must account for every last one. 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 <= 2038; -1000000 <= a[i],k <= 1000000.

Example 1:

Input: 2022 59186 -257653 -838105 913435 415974 -52107 108271 810281 757462 -822367 -283050 600826 160856 -756142 540252 -568847 -283997 326983 686442 428761 121502 -998498 175026 525077 -502048 18536 841164 283736 370145 -627575 800420 -479556 549358 -769893 317148 955703 146110 -590565 -566352 408944 -621922 851164 874242 -53438 80572 323307 795280 -371427 338849 866243 -400151 -202698 849381 -866170 -110616 117683 195423 115634 53492 360906 949190 -159623 699560 134764 920114 916784 -511930 -443070 836079 258941 -399198 803091 423827 319841 419971 172427 18522 194966 -852899 -114127 988490 63855 33686 2347 259840 315104 -349336 378229 140342 679151 798286 547539 -13640 544650 85839 616433 832410 -523253 -646306 993787 -133590 -667232 356250 212586 540026 211939 932787 776738 -594439 233588 182…
Output: 1044828

Example 2:

Input: 408 1358438 -466496 144430 28227 -955765 703881 -864148 -674621 -511098 710006 851153 -983884 257237 -995117 -310522 799464 881343 682340 -902863 9069 727536 32306 -874640 347350 908132 -534799 960584 -68039 19317 -966008 -979151 870343 46143 -457024 -246515 -311920 -680866 932890 -233594 484464 970571 -659100 -582006 -795591 318184 -809685 -697782 392966 554543 636965 581721 -5917 662947 260334 625191 494399 -655074 -847607 -730736 -101712 -542858 -676143 -216250 -847224 -527969 -130332 145792 -158593 943256 -210313 855056 -98691 -832848 -346317 914593 -653366 783509 940389 862283 978112 656663 622165 -221479 485555 130750 -88336 -685129 718168 963260 233259 -785042 -28774 -512774 136481 592801 267694 561475 -254689 -923064 446930 -806403 114766 -983832 -668840 27451 207829 -772226 946973…
Output: 78016

Example 3:

Input: 1542 909034 -140437 -705951 -43612 -990697 -785653 5971 863158 -354170 -537403 -683651 311347 -612455 135932 -44184 496818 90457 -129167 -38220 684418 -954261 840926 -691407 844861 -178708 276105 400733 789174 930370 599893 371988 625767 741449 950686 263653 -855909 -444519 360864 782736 790710 569327 764571 -917191 714189 -946989 -934532 515102 42913 -345304 946189 933140 748842 8132 -406164 -91430 818972 311815 -190753 863174 -306678 685809 -438542 542952 -146262 -121966 -244238 430141 934660 51827 935696 592710 -941905 28126 393136 659338 630472 -774972 -604137 -981455 -287370 -567133 -979077 685812 28285 276879 -224888 -173492 -231985 -790466 -575678 -703725 548556 -670225 945856 74972 247889 -689347 23255 -755946 692964 -916762 -775971 206450 649520 -405481 -128338 -958339 -564221 -53…
Output: 996474

Constraints:

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

Loading...
Test Cases:No test cases
No test cases available.
Tara and the Frugal Pairs - MEDIUM Coding Problem | CodeTikki