CT53748

Bram's stretches Frugal Pairs

MediumL5 · Recursion RenegadeAcceptance: 0.0%XP: 60

Bram found an old ledger of stretches in the cellar attic at the shale slopes of Greystone. 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 <= 3196; -1000000 <= a[i],k <= 1000000.

Example 1:

Input: 3126 952523 -696685 747077 543563 153197 81852 623553 296322 -369172 -349175 -953810 544811 795533 862326 443086 995039 504227 -260114 -270276 -833923 291330 -963065 -317075 -999487 833055 -843327 -336703 -538453 607642 -713384 758613 -178198 -274078 -61571 359211 -251736 -765773 -94106 -843098 -957078 686428 -249525 79583 483724 515599 637838 -473280 556920 -359910 967465 136232 -260074 741605 -824856 -799349 201654 -636115 488480 -572775 239468 581184 -434253 195236 -769326 -973461 738521 206349 659511 553762 360360 141160 -39185 5262 -287888 -960531 -407031 198780 945384 -969993 835495 -225245 -808715 102394 -585818 -199227 192073 -84853 874943 -20511 551481 328403 881843 454461 41023 -959201 801798 -546678 354908 738965 -57135 154715 341670 959248 17300 198363 536016 790176 -435962 985…
Output: 4184995

Example 2:

Input: 929 1696009 -38793 -246702 595846 608493 407468 -655980 -635096 772404 8894 95236 330714 -361141 -277656 675197 217763 905752 492805 -162947 -274301 -616315 798952 -834404 -916623 -962315 -112152 606693 968637 585700 -97696 391838 322363 525641 623599 -128751 123276 133642 -456040 -358734 -864151 332441 635202 -343042 903283 426732 -375987 974803 -538090 743428 -620195 -244780 -429694 660993 -822661 374544 -220488 -425989 563 -835236 -349776 -808764 -833220 -542497 718334 833272 54408 532285 170264 809208 395730 137560 -553963 -176596 -598758 -818654 68852 -697277 -478360 -475571 -847920 -935042 -24031 -331133 -685756 641107 -657183 -744156 25097 505044 39459 387410 905635 -805924 -724345 -343134 -380274 919682 -994842 660444 463713 499573 -893843 -704002 863622 113233 -686040 -583502 -355…
Output: 425724

Example 3:

Input: 1807 1376417 -453916 476100 700255 453174 144402 -912337 557503 -711180 -125244 -528180 -233689 -99424 299903 905355 -302212 -302974 665000 603173 813114 807042 700155 -60158 -857415 747589 -790797 722413 -401348 -329376 883290 -277583 714462 -531736 369983 -522863 644491 409534 121704 718446 739962 398885 -486633 -575872 502091 -499719 263442 506783 -708581 -866054 737251 -77704 -311060 -706037 29096 -924871 -90773 -772596 -631357 -115007 360504 -889657 -445348 -30705 363204 277751 357648 449373 -221700 -609634 -60202 -704657 -765417 -302453 -874011 120255 538937 706009 305443 -635421 421066 -939392 -975114 -417554 629214 -514220 -324199 -412747 614545 42284 826396 -130129 -887780 564640 -900643 -485690 264317 -888246 863710 -191890 511325 792086 804424 -285873 -127214 -527307 -806238 984…
Output: 1551753

Constraints:

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

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