CT50976

Xavi's scrolls Frugal Pairs

MediumL5 · Recursion RenegadeAcceptance: 0.0%XP: 60

Before the gates of the moonlit lagoon of Selene close for winter, Xavi must finish the scrolls 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 <= 2834; 0 <= a[i],k <= 1000000.

Example 1:

Input: 615 1375418 649101 998856 66244 117374 207126 818119 623493 3085 961512 213576 866526 952835 829721 134657 313147 589750 776928 522743 852025 8888 56238 351735 763518 103384 448121 300762 466170 334868 760903 530744 245463 687543 845610 778032 251460 293172 380283 44705 712222 653329 7225 261841 382006 930124 664741 95524 949463 193857 304961 361335 696315 495546 128594 821819 922289 969267 970677 820552 636634 918079 895218 508264 713522 685363 530877 852806 208912 622814 100335 600756 398737 703542 772235 624303 724069 244594 759121 299873 239046 126833 95698 106261 340371 338834 417396 507139 347824 149494 873081 330542 478411 709474 645186 83851 139197 445895 346426 410919 288159 522455 942756 284393 522544 12707 151066 275896 656437 161360 711328 275642 385858 437462 626227 223422 806…
Output: 156555

Example 2:

Input: 1927 497862 740224 371544 429314 569959 278001 789809 328605 698509 581850 635581 527585 593830 787886 218758 876404 298552 621299 54875 576254 37428 796117 906331 733912 317783 508320 39713 451515 317431 49967 464030 109501 819502 607035 306330 457379 527704 911819 810004 364083 613682 977985 161746 535504 456026 585874 779341 835041 476160 145008 932325 551805 402478 506717 150902 773447 692763 532056 447474 799029 62557 430532 244485 672969 950368 927042 755720 418389 710826 94993 831214 136632 323627 569338 885245 43205 583812 144309 892554 35385 273670 900527 732885 65505 815751 866787 503839 75199 173183 5113 310829 990551 44031 533823 482860 819703 601148 383777 889320 978888 962576 761324 300995 161655 190394 598783 269041 166131 923891 953668 790988 640777 918160 861440 241917 567…
Output: 246735

Example 3:

Input: 908 694874 491379 642184 271885 65972 484146 872271 858540 97182 247868 972742 877879 659693 403202 838517 555518 414809 469703 84455 733820 60502 808665 358157 560109 659309 714551 401221 818238 185731 60606 252450 8 3631 341248 2931 955685 940437 79168 883198 705299 607225 217011 177929 769079 643390 407983 145493 769884 652010 919155 537517 211315 211622 181697 103701 492749 572859 64630 933413 318186 609446 683165 81016 821755 460715 121779 81973 464774 499391 550339 499017 945427 544962 700840 123555 717295 762990 175365 860831 27911 977062 655613 71710 786114 169525 465979 684945 236801 2695 330038 255071 129231 196175 316142 995290 538026 587562 734921 883263 312485 197001 230473 762286 814687 923246 165347 793924 558011 470283 375084 493921 983178 617378 473688 820572 436672 309958…
Output: 107748

Constraints:

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

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