CT44028

The Frugal Pairs at Skyharbor

MediumL5 · Recursion RenegadeAcceptance: 0.0%XP: 60

At the floating docks of Skyharbor, Emeric records each panels in a worn leather ledger. The guild wants answers, not guesses. 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 <= 1579; -1000000 <= a[i],k <= 1000000.

Example 1:

Input: 311 968833 -972196 -242773 -568184 5278 297066 -443738 -804559 958983 -181675 240835 542012 909152 517481 -665849 -478980 -985911 361789 -423564 70303 -3837 -102626 597951 -908444 215806 -2582 156496 354525 243561 -676934 -166569 -724783 -514915 -107384 -927317 -567812 -744267 -248810 -715379 365637 692770 813736 476565 -711476 -839084 203419 772192 -479073 96394 652863 -231877 -230269 -474785 957742 -360335 -852562 288538 791826 -506685 818467 -91634 -802752 265359 -490903 770549 -555406 -604167 308952 -469105 -753341 899244 847234 818079 -271975 420747 591591 810637 -938225 312567 492109 -763894 251675 786920 -340977 -913328 61993 451128 -627848 929625 76271 -156976 -13957 486018 756379 890183 589231 291074 -815201 -282615 -411431 546301 -316908 -930745 -730689 -919575 905154 -915996 467…
Output: 40956

Example 2:

Input: 768 932187 -123410 781616 -750034 -248618 297138 -302858 -780477 -215800 -595213 -929111 -311880 215615 986863 -534912 -857637 -481697 -513972 397258 -537 -391943 -17162 -799366 -332152 -763328 766875 -57783 -169248 249593 665033 -776817 -926636 -880815 -483830 961779 970622 716207 -297807 567769 887980 -33658 -914047 883406 -860057 -915758 -120014 -885820 442275 88541 848712 309200 -869692 -794838 819070 76928 -40363 358915 -76685 29790 -893565 477652 -74452 860195 221380 158025 386731 -52191 448239 385316 154174 299928 -205744 -304815 -214225 276977 -601706 553853 449289 -721771 -67050 -76150 115113 22910 -787879 -9984 644044 235048 -130178 16699 -426592 -737060 186512 -237587 -573326 589343 35848 -59984 -991442 270803 982139 -975058 916055 -61225 -323646 -814335 -411557 710795 -499328 -…
Output: 253691

Example 3:

Input: 634 -766019 -154456 180078 -176320 438898 -54391 326745 127828 56211 -699880 351617 -410057 -529813 621986 -865958 -847920 -671798 -733909 904701 -669016 -655807 333953 -415556 -180425 161116 284138 414961 -350650 -333558 -836331 356012 -103977 917572 -395692 -426944 23539 -617008 488381 -474979 852773 -412701 130729 -210118 1751 498014 327289 948186 -435313 469619 -329953 810109 899059 -301706 -967560 993406 -476580 847946 960296 39413 83377 -224705 951574 373629 879039 36407 -111018 950440 -883455 309081 -26059 -259998 -710021 844842 -852963 332670 203864 -621171 576941 -665782 -599931 767754 989780 -288211 -582383 929718 604184 -758825 -712253 54661 -732103 -496294 322995 450587 68230 -98988 -799160 -362896 954842 62684 514892 -45030 911056 314669 397306 -832374 -970858 364484 -744254 -…
Output: 40222

Constraints:

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

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