CT31985

The Frugal Pairs of the Sunlit ribbons

MediumL4 · Loop LordAcceptance: 0.0%XP: 35

In the garden city of Petalbrook, Elio the scribe keeps careful count of the ribbons. Settle a dispute between crews, every figure matters. 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 <= 1990; -1000000 <= a[i],k <= 1000000000.

Example 1:

Input: 1868 340482073 873215477 329148800 933247866 325449848 117876684 435803161 438351985 993754607 885697695 849652300 787772894 578643373 453029645 927057430 822117328 675994786 377393578 814243589 337747610 816404768 961712915 926982082 353615809 511080324 59391252 142636876 258309201 637861525 151638232 365504933 764526608 613462787 73152819 729056588 681504418 458523843 9909283 485970512 783226632 313045750 855429465 620073668 639688169 44432655 426478985 250254906 605476958 547069539 567403343 346200539 444181882 206812099 655537061 728664868 78222619 742222696 752475774 913645052 684667031 405275467 712329972 197529047 685157863 413110092 932388163 794667206 667403710 844755771 719275451 959894310 699031133 210489060 154261885 283987638 247234762 768592294 336611891 575418741 364456290 1…
Output: 91107

Example 2:

Input: 879 898329116 901773715 591538480 313445327 276828968 411512961 622473984 299102635 213863617 398505202 340585332 520363660 330727218 809013777 77877981 260354706 362831255 160983530 756311031 136893907 766367171 818209643 634495396 773610256 935162712 980489291 846429208 894446969 580529954 242090085 868059937 840198006 887098937 929733241 457556623 6846763 410358705 921162618 550343265 630482257 808015229 856581078 708846210 979829791 489414703 586735886 665868638 422865378 203417273 676385693 64025241 337075226 703594900 102055639 905957409 238575146 657147555 332564946 94654515 995091120 881048325 893449240 710522542 155121211 112598040 944679446 37138241 743021185 447205742 292402351 684971251 592091866 241664769 563420051 857366445 279778656 276035642 292408888 617802672 385320799 60…
Output: 156668

Example 3:

Input: 1321 1726724709 430014295 932355103 872671747 546322550 515725324 201769797 308170957 672676992 679214179 670039435 846570627 23168337 951950687 199461398 491519781 39698875 300180287 59407425 727941473 561439225 507729224 494298244 922219931 103325625 921727213 381953054 586716824 594366841 321008003 754525227 469272786 383162744 861674963 268860082 67685840 573476640 474867535 860895782 770094558 7702001 231029748 411636330 304625412 34673683 867374787 101259276 901681720 314040091 236491159 503194316 919908622 56759020 948282159 316016825 983497032 122440216 737673969 748873498 370091603 992810219 680781183 587115591 539770939 829121891 672732766 434962336 428662848 627961166 266378123 103396213 742590897 325816850 105262170 261553195 976192855 681076027 448646835 932627407 392923924 49…
Output: 841108

Constraints:

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

Loading...
Test Cases:No test cases
No test cases available.
The Frugal Pairs of the Sunlit ribbons - MEDIUM Coding Problem | CodeTikki