CT51987

The Frugal Pairs of Prismhaven

MediumL5 · Recursion RenegadeAcceptance: 0.0%XP: 60

Before the gates of the glass towers of Prismhaven close for winter, Milo must finish the windows ledger - one figure at a time. 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 <= 1411; 0 <= a[i],k <= 1000000000.

Example 1:

Input: 661 1017039309 355584720 865652970 18670161 707985926 188341537 796837399 17415909 869082610 199783291 396329777 571356308 236500575 588085753 494668355 352733200 707118222 659727378 303788482 970167883 360669633 360217576 476462086 238395551 160368261 706958403 939187133 415236901 432252210 191143803 484658235 643426501 445103449 945502175 715972758 478157559 725430594 791322627 581302500 323473721 173490542 215126959 342662501 60471017 86836151 890922553 481034835 998912107 674530577 573678826 952100326 736569524 63775292 167152215 692820920 131020127 121523941 10836100 811532716 279524808 939183586 973169745 567958359 316349405 757300809 287747654 37586946 41086205 854685846 46268488 243370983 121396692 15803733 370282895 237057213 688591205 369794846 420063662 548099763 154093769 41593…
Output: 108603

Example 2:

Input: 1355 481514005 336551296 134797432 626341240 602980305 278131536 356225925 258223376 852156173 723493566 709206 550720717 926985785 778357694 429062540 656055153 468886058 869216906 602148763 891781533 660570672 254496647 89175773 57984857 494744570 203437154 101821373 717151480 22652400 862031167 531602807 864569731 662254944 58227249 538981226 433579970 140605792 296478489 374502291 746920857 866343295 419669653 712598645 731179270 218439094 219119512 425252277 455246074 713583619 450265485 220120233 779291064 305820754 616204448 185689572 705890577 104321797 867351137 668222691 671864526 314536743 561310208 284149090 67100143 935522361 850898118 479602532 528254734 543127865 808330439 283196565 596988757 402272226 742535233 649775190 791601788 315874720 468170950 101200568 744845254 819…
Output: 98290

Example 3:

Input: 262 1655599652 724483725 584172429 872262177 190849240 421282526 947557428 644410230 81672510 172063727 779366989 602257639 257492059 12274208 859084534 654303656 332260781 500248570 709646618 198881141 603990841 637485925 527242497 33800093 922404883 246949012 653947331 876678951 691832216 400461329 748000858 258629108 823830171 454903867 202090354 495402853 714695003 521622821 947748869 86909259 686928930 953114125 572735001 268592320 120487633 116108771 151406413 143390726 896663843 301791530 787989243 382406703 918153930 451859106 270479053 398219044 342107261 904706516 584201895 604429864 972470910 902743167 920192603 989947633 954902645 76991549 275797219 947367789 634513028 615480364 579361687 975214787 519595690 245698256 916823357 185534519 232634209 128120417 978255972 394684017 …
Output: 32033

Constraints:

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

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