CT36268

The Frugal Pairs Beneath Duskwood

MediumL5 · Recursion RenegadeAcceptance: 0.0%XP: 60

Legend says the vault under the frontier camp of Duskwood opens only for a perfect tally of panels. Tinker means to find out. 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 <= 2287; -1000000 <= a[i],k <= 1000000000.

Example 1:

Input: 1630 780580604 153738704 173039005 884482078 435167567 27461415 101436399 830382055 41370142 405922698 702786317 745775705 970777813 238459075 558500184 591149798 593094579 270976562 890682426 509239421 730142705 358928689 23776685 293636153 632640089 169164876 557973025 726355168 808289293 930792557 159103667 613673491 365155506 521582383 164845994 869393394 978217191 975679035 78607338 691445601 96155964 782928212 852279124 170661525 487595731 359006351 37320069 622409123 531620775 383172357 683629656 920473654 299001118 498479328 200537268 992778811 36325194 186645728 297340422 429323598 629375891 112539194 526246040 834629707 377334918 754930100 942788149 483080078 714638734 834661919 854486788 619164127 574553433 96434044 634807022 544070700 340219123 912088085 751294018 616917488 985…
Output: 404630

Example 2:

Input: 369 762206064 167808013 886724788 392802548 862665938 916834441 242291092 588757345 444933283 513548897 500796549 361648018 903852660 703882181 44882616 796259932 321969283 813217195 327174481 351773966 30237276 817715908 127680268 124412765 65001188 606596956 898816671 846322522 363018279 706301559 533187216 453912779 502240769 911930254 621366390 120239913 223236192 477968580 254449082 608836860 470667532 51407990 522573128 916037202 896878469 678036143 939864810 957244837 395468507 808998688 765461304 948928519 578461123 969563215 882935131 472735388 367062010 437042287 7289916 388198529 547308095 915467259 613535599 11833503 86644849 561510713 502709445 815919701 351923 330515691 205991549 996408201 150211852 536268276 657201859 843832058 412066775 572517446 162238925 396664908 8592572…
Output: 20323

Example 3:

Input: 941 239834143 160376621 464765513 351213212 581758834 550882208 613796924 404376720 174181269 566154940 453408553 128871840 55560187 917526042 614229167 497844626 724315611 521499551 473630000 798099720 208731157 844575525 386674896 130383676 236916330 737717388 853672812 766833380 910020243 571223975 864192752 353477795 71177409 742561 75668370 193862785 926488107 344300695 334747670 310775976 959063442 463195654 533592464 140608055 324545772 26287602 703911105 71722451 299332380 503851471 485323402 191759769 809067842 561731279 620739126 544121005 576534427 699750905 746285875 988296456 455987690 811543946 624471578 238345783 683462116 75646703 129249045 375935676 6172183 723443657 299479986 139345561 504802020 115665630 249962795 813080419 170367464 18352957 319906698 190391547 20698818…
Output: 13759

Constraints:

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

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