CT32666

Manav and the Jade scrolls

MediumL4 · Loop LordAcceptance: 0.0%XP: 35

Manav found an old ledger of scrolls in the greenhouse attic at the tannery row of Leatherwick. The margin notes pose a precise question. 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 <= 1886; 0 <= a[i],k <= 1000000.

Example 1:

Input: 470 664715 466815 173086 216775 497198 821894 112440 420343 871651 395807 787161 354289 784995 363144 610894 48644 139848 229060 41759 255229 32809 662450 939207 695671 811260 879593 242923 510317 862928 763970 61648 600482 539034 998809 211861 649877 118179 638444 743585 975821 939010 251057 681606 826044 313200 505122 381716 318330 676075 814625 206068 278929 794427 105857 757140 280554 497095 76288 760749 326950 227135 78514 468641 370784 5851 948545 805475 244782 337610 362799 431617 647077 854686 133205 253943 175121 378558 439819 339555 406392 65247 510857 908190 745926 476247 511821 260772 431169 718131 68442 969834 139304 834735 798120 276785 905424 872230 89798 377580 820104 207330 967132 49028 806193 62233 246819 349191 70683 11270 318488 757990 658770 223868 865839 454423 497342…
Output: 22232

Example 2:

Input: 1360 860920 339098 229762 198558 308229 18166 747444 379700 522509 255184 26776 928369 343037 749126 800381 786664 986872 525855 678984 337565 447033 802032 153725 541805 861563 595804 713045 163185 504873 800724 662117 354846 228770 20831 960230 905845 189044 129347 710060 398291 63399 734887 727404 312797 444845 68254 348710 528905 909520 962015 578546 370560 428503 323409 685859 90846 76273 745751 886078 471763 799172 389386 681849 583588 237202 471028 908365 878258 595260 638345 957576 152191 665960 12247 227031 503327 435637 604084 520721 515589 276221 108708 271815 586068 227366 267603 275659 733559 314342 168511 978638 400027 343002 416143 667714 101747 777875 413549 698880 610711 637842 645095 130764 631066 341868 455155 369410 289005 842560 417000 132017 72754 98070 354196 683744 …
Output: 339524

Example 3:

Input: 714 1885196 583015 129380 470038 248827 403078 223154 327007 332536 889962 197286 707616 121991 193719 305213 291050 320932 984406 239532 865787 900330 548598 512134 89280 281341 965919 549985 499022 833259 524118 433639 481193 71508 819943 620003 432415 289285 722688 750439 807867 984384 844338 126327 490921 477154 619652 543844 438356 268568 357434 647435 821480 915805 881525 488685 593326 844174 652204 463338 683382 902837 32258 534952 834626 286670 945884 997547 99569 450384 724833 316696 540122 77543 917884 615642 377358 22769 499387 963085 276303 700156 956167 699435 88365 880415 930777 720263 874498 112112 459842 162388 434935 557386 960936 814351 919968 125606 257330 571596 142797 315227 884063 315227 510668 982506 601341 812863 970015 437916 136732 85647 678155 63140 666767 65372 …
Output: 252313

Constraints:

2 <= n <= 1886; 0 <= a[i],k <= 1000000.

Loading...
Test Cases:No test cases
No test cases available.
Manav and the Jade scrolls - MEDIUM Coding Problem | CodeTikki