CT46194

Brevin Counts the panels

MediumL5 · Recursion RenegadeAcceptance: 0.0%XP: 60

Brevin found an old ledger of panels in the cooperage attic at the bamboo terraces of Verdantstep. 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 <= 3216; 1 <= a[i],k <= 1000000.

Example 1:

Input: 267 853630 454146 829291 465168 35725 376272 466450 86174 418510 619598 174393 16516 719973 209158 696765 564634 314969 541569 357400 349331 7254 301711 146127 736365 491990 868532 282435 96249 622072 727699 622478 993431 73912 82626 322347 585952 667119 459103 358269 312833 134417 544465 168873 409043 898405 723381 582645 488059 373471 811673 516271 990529 117763 934971 682810 780419 971138 557085 394079 613108 839543 715580 121349 528825 128372 401546 58949 59503 10580 200786 741601 47344 53447 783134 577494 699544 458013 144289 653318 392911 145901 563830 30750 767241 396426 446673 420280 248135 578954 952736 111543 71608 272856 842996 29191 50307 29249 505409 794606 809184 831730 593809 426224 726377 751241 939814 488354 275483 824970 506423 76531 41908 205911 411031 766594 532650 3184…
Output: 13010

Example 2:

Input: 2440 1793239 802430 407567 625422 160591 431275 262822 530742 963440 741564 682674 244189 345508 396777 865379 808431 61036 640414 319590 749977 452716 881849 926054 199683 5745 102283 211939 932163 893524 11590 622395 569842 250071 549644 453431 473818 781560 562873 72577 49152 277315 930816 285883 256818 674330 247850 937995 510927 67006 457868 702188 823943 359038 422760 49952 442400 493073 909614 117530 15113 399552 125017 218699 325003 320756 771211 242698 691285 310197 295435 71480 582132 427014 748407 777770 308800 674156 48683 81675 232418 310644 713787 788143 932950 616005 250711 761794 212437 693209 772668 505449 916509 66460 299912 965084 180267 456911 740003 950840 443971 886633 719453 750742 906766 933609 218637 591743 910239 378123 179748 733149 754311 616290 976691 252764 93…
Output: 2909091

Example 3:

Input: 2937 638451 813448 957956 675573 992765 34533 872604 689774 598900 942683 932641 107325 361280 855576 411219 470588 618160 68399 793052 231163 67603 138877 643793 120190 591335 426294 693891 139955 509282 662824 383739 975849 915432 69479 385891 484767 303467 200169 49109 797062 999692 571946 811192 763642 590818 598021 916495 813128 318405 487171 467969 128234 96783 315646 449530 579967 134021 354252 142230 565368 902674 599965 199387 801864 551249 521709 909023 242216 535371 597459 560954 45677 672021 383413 384129 564096 217866 338217 729799 608128 144949 429902 474306 786965 395245 385044 263255 454392 429343 680778 467593 619186 39525 39614 696787 53640 815573 238103 474566 219660 79492 656869 130429 197462 274289 92457 173289 550656 325554 153807 160218 496227 43793 67998 931509 5958…
Output: 843590

Constraints:

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

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