CT48207

The Rainhaven Frugal Pairs

MediumL5 · Recursion RenegadeAcceptance: 0.0%XP: 60

Gardener inherited the brewery at the monsoon port of Rainhaven along with its curious bookkeeping system for windows. Time to make sense of it. 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 <= 2272; 1 <= a[i],k <= 1000000000.

Example 1:

Input: 821 580751333 139354862 664970054 22725598 632636309 165706938 595091290 224878933 969580260 379333915 118173521 750087142 147261957 431606778 474671660 893270274 243703271 2085594 885510410 925310943 845991711 491686877 12814518 14517354 874784259 159539572 723430561 698765495 869189457 633423999 439976219 575491353 217439986 962555219 982506364 575745550 989403127 158044558 767866798 787765161 726488841 91258370 490198033 218979420 152852362 861650173 959796635 108200256 178450832 118581044 633377456 19122875 997331343 794997719 265419234 810666459 924259145 243226506 264550443 979188224 487831122 335970505 657553172 210856117 691474489 280885019 240016309 767990045 343865868 244121344 483628026 451334011 411926595 234831329 593615854 771621183 172741832 11472472 391964463 765443603 4211…
Output: 54825

Example 2:

Input: 663 301390185 886853400 362969962 229244018 577323155 161109111 16108222 818701340 876407356 415408517 896106667 596789113 19207297 481218698 830598607 136732552 769748460 17785727 422568148 985673912 679681410 653307246 812803878 285769332 425680015 212616061 719621065 926067947 632155573 470413546 10700489 913589908 275998269 688505188 493550482 530640549 426553013 440027214 326346912 978762651 957982798 161676297 636040389 204089361 291234706 898749083 216339761 621641915 147549506 536612769 411982348 274039956 122592108 236861561 450394915 938312552 572747526 52933850 202993703 577303044 917247536 779143938 347086566 867879174 294319756 481484587 415133376 253160912 282660240 156574294 621792282 213512516 432671331 319180789 717617964 459077437 356848271 142051448 975223237 248005063 4…
Output: 8895

Example 3:

Input: 1919 860814505 842718903 367208878 918099994 345351332 503370727 66707265 381053797 17427280 134512211 327668474 106545091 628972395 715746955 182324852 604926851 939960742 51054179 889272065 320009740 930439823 940229596 420226020 899929975 696612926 591371431 522942587 717864631 652586669 68019076 940078813 911093015 176481363 603112668 525685883 354731966 319137814 13842621 886865319 518104553 442705987 980579934 26874774 812600818 296302795 290116990 409982821 299640492 770723412 729546023 909737724 416138759 302006262 144332794 134808465 881173575 178999465 915854966 783191877 577309540 395632196 663088518 519895250 712251016 162991451 241446385 724637544 485208054 973968146 710239373 618376825 291745324 966277720 192065040 397766603 575182931 977378635 934867132 817571090 244177883 2…
Output: 696113

Constraints:

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

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