CT55453

The Greyfen Frugal Pairs

MediumL5 · Recursion RenegadeAcceptance: 0.0%XP: 60

Surveyor found an old ledger of scrolls in the chandlery attic at the foggy moor of Greyfen. 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 <= 1221; -1000000 <= a[i],k <= 1000000.

Example 1:

Input: 523 1660587 -723340 471536 -506856 67039 -909735 131334 942721 571611 -456219 -558358 686099 766109 926112 -634786 932633 -11423 363025 884906 -612826 713800 735293 976199 -975821 -124597 855099 -909921 -296809 -960168 971652 117266 900043 -918403 -633617 623641 -564219 -659890 -105166 -458952 933638 -442190 -204688 414584 -458517 370943 -865468 871049 124289 -708064 -558066 109921 -759519 947249 211976 802071 -250409 479692 -46309 -418406 -550772 -498697 992347 815221 845657 550406 -329776 100137 262820 -950261 -67085 -237804 -955236 -28948 -46854 -214240 244713 -685461 -681382 -916251 -23727 590357 482691 713757 -473591 -913602 -730370 377120 390279 471201 -41254 883240 944898 24668 -496250 329738 553711 76111 875321 129540 -645269 -849017 884823 793449 164370 -600622 296968 423276 32834…
Output: 134091

Example 2:

Input: 767 1344555 -590140 -125779 -680394 -211323 501056 -883287 -229790 -336453 118521 -572221 -517316 -614021 -536216 855142 -509959 254809 99770 -281511 557852 882942 -918579 -474759 77966 -92240 -247636 627132 -830121 -1736 -441487 -320413 270187 176073 -108080 -696622 171818 -510660 262848 -565942 510928 -362242 545636 -279457 123795 5541 480640 -258737 654862 250339 261372 149437 -796327 143886 -781821 -701780 479197 202 -359942 817100 77787 -603041 -67343 700436 192260 279235 613781 -65305 -921752 -524255 801806 566245 -63977 -3137 150663 566129 95461 40021 41269 -851883 408593 673341 -174481 -131226 -899105 -428424 82352 -346856 271786 842353 -470780 869150 178323 -471324 -410102 21844 924717 -393931 916444 469392 655235 847503 -415168 -755108 -663065 -737696 167846 -640089 -595681 52489…
Output: 281494

Example 3:

Input: 838 1479758 575513 188739 -580295 -493961 -765976 100218 -335355 -272360 676822 957397 -528669 678719 945210 854154 -8446 -718195 -118023 118757 451241 -298946 715645 174290 -835099 929520 982749 97847 -475386 821552 944619 -887792 -350590 -87872 -348545 -835515 184396 986817 -755085 -301072 -218649 251387 -206707 371373 -281245 619590 575940 -444854 -126707 -781108 -767387 -241464 -55716 -156121 551979 -45717 -61835 599295 342504 556478 430882 -19826 -853007 691265 142989 884550 773491 80318 839349 -59601 -437991 -265479 805742 759842 -381843 -828279 -927935 -6833 -427271 -193931 -183927 -18217 269987 659705 287002 637384 721835 413791 -943019 566504 -172533 -912044 892222 -259385 -279363 -351100 731504 973109 -70755 878317 -233369 -943752 -947593 843658 -272861 -855349 -776811 -546291 -5…
Output: 337339

Constraints:

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

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