CT33918

Wren and the Frugal Pairs

MediumL4 · Loop LordAcceptance: 0.0%XP: 35

In the spice bazaar of Saffronia, Wren the archivist keeps careful count of the stretches. Compute the guild dues owed, 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 <= 2875; -1000000 <= a[i],k <= 1000000.

Example 1:

Input: 2099 1109489 -906898 472886 -803704 -54312 -324485 463510 -158009 -560748 -104596 -902346 277179 310702 -228844 -205834 -134263 960101 -640299 457459 837733 -415760 -461924 -659742 205388 490097 -583212 -932671 665275 621667 126486 866887 -612711 -795587 717198 -264892 -818654 540250 27946 -676869 506935 462338 736372 -973718 -937281 713399 423844 723242 -119339 207319 -825895 -994383 990762 410370 219503 -47770 200165 -172717 420447 -473472 305683 -440254 -476748 879305 249482 -184437 812354 961669 293717 130479 -281633 651603 596821 -839462 462473 127367 155385 -480447 -363179 51879 983262 -186427 811555 -619514 -148442 -969373 -369366 -984658 886896 -230685 -303246 -43237 -406553 -201278 -617258 -352534 -292023 -381760 -916364 -148465 -394939 -461285 432510 -487231 -683314 -953658 -8624…
Output: 1990734

Example 2:

Input: 2213 1810041 -259295 251011 681821 640725 -681095 60842 323596 742173 -178083 867024 813681 -417102 154944 -749843 -782056 -781789 353706 97313 315866 332544 259762 625006 -16033 385670 -478907 -683044 147274 -539081 417732 -448284 391511 647614 -145247 -465652 826647 244267 -331379 -744207 -437915 -103145 -545577 830676 947274 967087 -285430 952216 939981 481761 -960389 13038 468443 573410 -652611 -957422 285174 680578 -806354 -601119 -96821 -613980 91900 -315447 -451089 181554 775214 196523 431513 -64901 622027 312342 -667223 215546 -574810 627264 67882 -318681 -546218 722456 874774 -425287 -438111 -147390 416458 -903650 -923116 904525 378478 -240930 -833794 36850 1040 -112618 -219848 32045 163563 -799391 -839778 318173 356639 20269 698793 -418767 -224707 291647 109928 365911 680478 -172…
Output: 2437624

Example 3:

Input: 236 1329798 569846 112692 -583636 -481675 -431305 192860 -30024 -516132 173745 438551 765677 -76473 719102 -103404 926993 529355 -214455 381703 538850 412696 562482 -349077 397258 451976 991801 310007 52747 -295739 973408 555339 126741 -211342 -146221 333075 411967 -443972 865163 -704898 -138183 -864533 865801 791950 15569 -256695 25636 -194145 -935929 -661828 -490821 987350 785422 850130 -935631 -538882 153365 -784773 -883178 -169460 164032 210645 977736 -386544 178270 -777664 359660 14018 -632697 -546234 678305 -954236 366811 977756 -846250 170084 -963831 -317817 -70520 107419 764807 -36658 586970 706081 -216380 414142 360175 -85058 -100599 313115 403810 -874938 206707 824453 -26862 -547328 -923446 158556 -488814 159068 789490 -476895 -263100 -774494 -284058 551306 49361 -869450 -694417 …
Output: 26092

Constraints:

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

Loading...
Test Cases:No test cases
No test cases available.
Wren and the Frugal Pairs - MEDIUM Coding Problem | CodeTikki