CT48653

The Frugal Pairs at Gusthaven

MediumL5 · Recursion RenegadeAcceptance: 0.0%XP: 60

In the windmill fields of Gusthaven, Jace the inventory keeper keeps careful count of the ribbons. Prove the quality of the harvest, 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 <= 2539; 1 <= a[i],k <= 1000000000.

Example 1:

Input: 1947 1265695330 259121732 593431056 685739478 969299141 484914855 444213190 17786808 803397399 484978996 489129782 459817372 882295880 658097013 273761416 724350866 67218122 92825936 498755306 78024366 299469691 355846924 398765683 11317643 989433053 824747652 827308601 90886606 834467539 915545788 121547866 991680808 130384847 622260015 373522851 910830644 532363897 349970267 620271369 682349637 493245661 852219034 614265716 151427078 369036182 946373068 825232094 872337011 87603639 361514770 995546963 647470807 755380789 647156245 372948427 333670408 893902833 510262736 448308175 956684971 495138414 355594795 397153617 81667018 538256124 48570644 101616036 708876452 890358343 422594381 73114238 172769467 439964326 267397280 400268694 610378999 802479987 166468932 142818137 886287887 8523…
Output: 1365392

Example 2:

Input: 2177 1493983749 537983231 172668510 523617980 926693712 156406047 783856539 124821886 922997520 236618915 787386051 326559721 101845724 143434558 623538580 672548449 549417585 416693539 89386756 744407041 958201408 613645379 257706538 936930676 819661475 770485179 336566670 625428132 393752181 364549889 898736275 306890383 797934452 500425144 581194832 130571943 430723194 695594889 635357057 840705184 261470165 996069282 15382299 314987739 859090324 479303242 679511983 614649460 980351156 614910298 551558712 668214025 756989203 858167757 130216825 271817851 576033368 138460827 470268861 820575601 2978620 948977904 175541138 49117134 394474468 883840331 961219245 292280254 419067540 430923743 829359301 118569187 878446361 70973740 682936681 313650508 960445637 373586955 285378170 966382113 …
Output: 2073291

Example 3:

Input: 2176 374956553 206321672 969811565 829065332 57368266 633727119 977341658 844883207 11907534 753460686 792539649 532897917 839677388 382050222 981422067 133296577 567865124 970222540 380638892 117035279 273356895 569465444 369769411 135913240 293886345 666026416 162749136 574757272 402073818 371217932 991144560 785274492 128033748 308859566 343456629 106780152 82639882 57262665 655236527 319985243 669662170 707731089 492512105 595042990 198694720 657981739 72296515 616093063 297890997 580283721 531239161 503107914 201708967 361564601 977362864 189927350 388594844 568281261 772490850 851814268 54240255 317708874 475255202 333020148 499473258 920706530 572858527 472037932 147258305 757767484 386570222 984819106 808167667 123924535 394980130 928833690 811622979 808101894 578724665 610542484 9…
Output: 167049

Constraints:

2 <= n <= 2539; 1 <= a[i],k <= 1000000000.

Loading...
Test Cases:No test cases
No test cases available.
The Frugal Pairs at Gusthaven - MEDIUM Coding Problem | CodeTikki