CT43838

The Frugal Pairs at Sunspire

MediumL5 · Recursion RenegadeAcceptance: 0.0%XP: 60

At the temple city of Sunspire, Zara records each ribbons 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 <= 3432; 0 <= a[i],k <= 1000000000.

Example 1:

Input: 3065 539935477 594789271 813640577 743889309 162726840 781797138 395361051 649767338 452235477 775890287 611433909 775742126 764727342 694349953 100761955 562494569 511253545 296429194 374394375 450555201 584949 935847769 530426246 417198983 772259197 785444406 974911499 940950572 672903659 593741855 558695832 511575475 819010749 631334546 240317742 6702755 378515990 227098633 981424457 989124883 106429827 161315674 73500170 705289256 510674815 885378843 323267591 278365793 139045677 193562527 609309086 661493482 700204457 435070539 163095694 300490258 491064791 714999385 235776407 408525316 131305955 501425217 177135737 46262469 282030175 488908146 438969671 50933198 664916518 746744084 784332927 742734945 351641223 70007512 36644462 325596126 945632625 977922809 891429728 855386514 28609…
Output: 655607

Example 2:

Input: 2749 208777926 953625731 931978811 100847656 541089447 196250511 887959401 660023251 177561548 422494277 641559168 815282293 294910648 568037604 778371896 325891190 260213792 812893144 39603425 567480760 649174955 588038795 837299300 425765465 410415809 646700479 558399429 658823270 237741172 902471340 740784401 403008398 547766793 659997603 408388367 478409483 20979426 131189311 321064258 265693892 715005607 838034986 874862428 679677056 181862365 560430052 783455803 847207797 685205874 328067981 357618833 863230870 620255773 44213166 832094682 496837459 472922507 661053420 226024577 325547781 420914089 768386483 994148530 119008977 249699283 825236656 740895979 880450421 972756010 649070704 637805573 659661415 494980823 411760897 183723778 240861933 75054578 577883819 506023535 322512788…
Output: 68729

Example 3:

Input: 686 147462447 867197018 673322701 590370778 379131643 916391199 969992592 618802994 882539755 207844308 51051503 729318192 992505341 384775227 335017261 843426651 584941290 940165644 456609608 899221605 596858369 837454137 723339886 43089795 400454298 708121489 345635839 574877243 791619812 943895343 964569551 471691673 88844383 807151037 887359277 56063202 301580006 688785260 551549007 937729278 859739937 685042667 359754394 301735290 440926892 334573808 876210425 445302201 824233115 434467781 338178575 291350105 991676029 327393859 445684860 271191647 754784810 288913248 770917852 102767106 448719529 694800227 173218213 283001983 284234145 321070200 138595898 201275163 513093912 545179137 847914954 448391185 136392703 336467843 442276225 705652421 573026580 81129326 50860130 829782919 95…
Output: 2139

Constraints:

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

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