CT47318

The ribbons at Prismhaven

MediumL5 · Recursion RenegadeAcceptance: 0.0%XP: 60

Before the gates of the glass towers of Prismhaven close for winter, Captain must finish the ribbons 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 <= 3433; 1 <= a[i],k <= 1000000.

Example 1:

Input: 69 966008 691739 389944 570926 653606 285139 644623 688246 779962 136629 646673 976697 5502 305533 907706 872078 879151 814420 198763 429222 754117 792478 370070 577976 342574 65503 106501 474665 495281 36953 70354 686445 805298 229107 761004 491859 566643 312403 571137 823709 361107 587635 864548 758237 274119 246636 974032 735228 83917 78920 173189 442670 111416 937407 784810 275943 261813 300312 939038 839653 403971 283151 737080 341132 70647 481361 159777 36803 796744 328002
Output: 1131

Example 2:

Input: 2247 1033276 576230 910603 785171 639720 33191 958460 489872 709554 177596 782951 486651 856609 258069 353649 776020 366619 715597 960618 103570 71532 620114 39189 395226 122303 996883 31376 263093 103759 465673 133817 985950 22950 870384 647992 265180 734988 979346 61753 11586 335203 946969 570756 330165 824783 764020 629240 678370 463135 714963 834143 485829 345443 742166 234189 425596 64489 435455 17938 662752 231444 343620 351217 106538 132892 218912 989335 278261 922196 376740 619369 880855 58779 138186 730904 823564 607916 215803 488565 489887 42183 875932 486336 907486 253883 622228 988332 333512 285598 825928 602034 801168 509781 240191 51074 271916 842748 141101 163015 183204 646960 859769 762856 724576 528648 636602 783218 290052 824861 800602 728928 535197 182891 291586 952470 6…
Output: 1335457

Example 3:

Input: 769 588176 147760 5065 175297 867007 225938 604890 411750 728123 659286 528596 317108 430945 332329 80226 95682 634767 13737 930125 520530 160782 924033 788016 257633 907119 474532 135756 359743 518000 502940 169091 886572 26345 220508 863285 490855 366952 755319 911912 941132 97419 697567 325453 468260 833960 496299 429490 846292 761269 602702 393574 717803 313199 381126 111283 105817 264993 40433 876885 202151 45184 599695 321943 405454 983380 754799 564265 280387 25794 955828 452211 959299 167548 299991 412715 255837 43553 558028 262254 612278 102352 50722 429903 848333 950351 821826 204382 270393 719888 509421 497983 60050 941509 771611 630501 732928 764259 729262 172131 871647 637655 614123 48894 103401 126575 649406 113883 960937 758003 563937 462284 274442 417707 107723 817081 26354…
Output: 60998

Constraints:

2 <= n <= 3433; 1 <= a[i],k <= 1000000.

Loading...
Test Cases:No test cases
No test cases available.
The ribbons at Prismhaven - MEDIUM Coding Problem | CodeTikki