CT56900

Farhan's Ledger of ribbons

MediumL5 · Recursion RenegadeAcceptance: 0.0%XP: 60

The harbor bell rings at the valley of Misthollow; Farhan weighs the day's ribbons manifests and starts the calculations. 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 <= 3147; -1000000 <= a[i],k <= 1000.

Example 1:

Input: 36 -228761 -122489 -858081 -86470 -381757 -795280 -492939 -366705 -192839 -294715 -137002 -74671 -133933 -757716 -207473 -777472 -237579 -875449 -76454 -355484 -562719 -464685 -644309 -22848 -130214 -528037 -627291 -138737 -563984 -106532 -870866 -243445 -699565 -767552 -212255 -565272 -47941
Output: 589

Example 2:

Input: 1319 -634669 -626211 -350196 -181745 -69452 -655356 -111762 -532289 -511915 -249531 -894666 -511522 -346646 -849713 -257865 -442703 -33907 -838723 -257171 -572656 -837004 -717327 -495933 -265556 -663288 -240722 -515534 -600984 -465278 -503064 -212460 -745628 -320200 -731813 -210952 -299249 -99951 -794504 -115854 -238461 -577949 -667670 -178761 -30999 -31087 -371565 -79310 -314971 -460360 -375492 -469081 -123070 -524367 -806763 -892884 -422408 -219614 -741845 -170444 -757079 -634387 -178877 -665892 -356227 -386988 -569154 -907662 -766354 -159534 -748663 -537894 -997605 -358854 -137602 -229755 -3479 -929582 -448301 -12633 -225336 -308995 -121003 -632901 -90836 -194506 -939764 -33775 -340385 -721153 -978998 -929951 -35722 -482884 -446475 -726293 -529896 -636957 -876725 -918070 -79178 -711899 …
Output: 673449

Example 3:

Input: 1919 -390589 -30129 -704258 -705767 -408320 -141828 -766828 -733632 -964488 -551085 -677249 -945404 -668185 -383705 -943762 -465486 -725429 -640392 -221364 -403697 -564388 -717322 -877881 -823933 -643937 -959749 -493516 -934349 -157209 -716719 -544819 -768842 -539325 -947340 -218581 -624299 -919863 -876692 -825003 -681861 -898621 -953908 -959373 -602543 -558202 -598128 -185572 -80838 -879640 -644924 -347827 -933323 -728559 -80874 -98797 -914913 -84874 -520440 -484028 -554410 -41812 -842707 -371639 -319872 -31029 -610906 -183709 -372328 -562711 -537140 -517096 -908030 -496830 -410532 -343572 -478950 -652646 -567315 -504162 -639616 -113043 -87754 -228938 -924485 -937425 -836438 -712692 -100623 -421556 -83418 -42187 -384412 -261716 -720802 -443066 -664525 -510695 -178174 -703152 -405512 -2660…
Output: 1716907

Constraints:

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

Loading...
Test Cases:No test cases
No test cases available.
Farhan's Ledger of ribbons - MEDIUM Coding Problem | CodeTikki