CT37283

The Sunspire Frugal Pairs

MediumL5 · Recursion RenegadeAcceptance: 0.0%XP: 60

Legend says the vault under the temple city of Sunspire opens only for a perfect tally of scrolls. Dev means to find out. 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 <= 1384; -1000000 <= a[i],k <= 1000000000.

Example 1:

Input: 2 1131974254 915202873 53406813
Output: 1

Example 2:

Input: 534 26344919 462717210 590853375 561776395 833698893 814627697 475907458 83064045 768885555 486800484 216373224 737829154 755978770 263629978 484549752 159726310 754385144 713689621 792544850 277349352 193240006 283440781 663311585 517583655 17156863 232451463 118795410 324066434 469017560 947018266 296996184 995925333 632139619 864464545 298831757 331429630 408489949 508239194 882509460 769148611 886221642 740873509 239453532 71280811 344762652 915306836 586356382 749445190 777326573 102302930 489820748 85030264 522411887 718166292 937003437 463035212 800793396 203823528 364280377 899017305 683936347 103978790 729796704 386208617 641257966 521793252 114990758 882463927 78428453 779878678 879940910 478962616 600275522 23650705 275703830 384461027 448477617 579259654 32476316 587564368 6660…
Output: 26

Example 3:

Input: 1246 595944189 789041991 822765853 798276277 829764499 333964084 417791811 536966673 810889929 131684664 943569440 295264928 274993337 957508764 637009371 336974408 115168759 763619022 856704488 731788529 823527171 583376497 527670939 795164047 510825642 542331538 908440966 98664449 772632584 996770269 537807579 301712293 822327558 160740725 483331652 462208290 124921281 793484611 808684715 794176417 72370396 247287469 183725837 817383199 732533896 931683152 514735010 553003342 194471599 702864073 941785402 791987078 825189945 567167883 647299708 3621699 490386448 763580054 492150678 917409817 193837071 731886469 454229365 874604242 700713151 445773614 67666798 780844941 366507059 750317499 485611991 825170061 521873543 662949818 59450184 544841450 311818037 673098457 498957467 644995912 6…
Output: 128971

Constraints:

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

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