CT34226

Herald's Ledger of stretches

MediumL4 · Loop LordAcceptance: 0.0%XP: 35

Herald runs the kitchen at the granite steps of Stonehallow. Today the books show a list of stretches, and the numbers must be worked out before sundown. 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 <= 1754; -1000000 <= a[i],k <= 1000.

Example 1:

Input: 885 -629190 -732079 -385672 -21264 -213364 -107401 -178948 -251002 -148733 -463071 -938349 -693047 -213443 -90804 -733084 -18119 -619761 -925032 -948414 -275066 -669511 -642940 -836264 -235207 -735859 -14115 -696502 -837611 -932535 -600981 -894537 -238807 -740607 -232035 -99678 -133315 -487357 -505377 -41019 -605566 -44955 -559896 -536471 -190854 -60537 -271286 -787360 -441979 -371156 -1055 -767919 -329212 -976683 -478608 -751391 -102024 -795108 -90967 -645848 -385844 -219529 -621543 -447217 -53987 -656447 720 -282870 -4123 -455872 -194237 -531512 -142107 -390695 -998733 -329559 -156892 -271407 -653377 -497105 -662371 -707327 -254479 -13513 -922810 -392369 -118869 -399702 -849945 -543024 -316576 -47952 -114903 -659563 -784088 -673692 -921050 -90976 -432185 -29032 -893682 -313592 -238565 -3…
Output: 319205

Example 2:

Input: 669 -490450 -415780 -611508 -203319 -277377 -218027 -366896 -38767 -453909 -305327 -287327 -531934 -839725 -656166 -237830 -441660 -169376 -623379 -656618 -416392 -89682 -547777 -788333 -212739 -16975 -514372 -908441 -871745 -729363 -97385 -178619 -330830 -826439 -385554 -232486 -852479 -518670 -602165 -102266 -724333 -543530 -519980 -70958 -719603 -533312 -592114 -65867 -234385 -890448 -820958 -927972 -781000 -759524 -841300 -391645 -471698 -584141 -201096 -823331 -815941 -566936 -395879 -450643 -744213 -790933 -771767 -216521 -564603 -820082 -457207 -25209 -605453 -977398 -268733 -455028 -695357 -867245 -523951 -901381 -626532 -555573 -729647 -695499 -89010 -666931 -76333 -412590 -236957 -567368 -779556 -729093 -508440 -366381 -521161 -698091 -152133 -278564 -436182 -9339 -344480 -737555…
Output: 197548

Example 3:

Input: 249 -974208 -372410 -971381 -408814 -458642 -537828 -200645 -694380 -253711 -590418 -109040 -987530 -549631 -871960 -485185 -76320 -742351 -128531 -897249 -286932 -36658 -486216 -186907 -540858 -577770 -185808 -660322 -26796 -126704 -522505 -191241 -640079 -229097 -883883 -718307 -437037 -274645 -92132 -30891 -238596 -919587 -608770 -405213 -598512 -546707 -36509 -216619 -337522 -90617 -538767 -490710 -783326 -17074 -651090 -661102 -816969 -893184 -447118 -216086 -760781 -977349 -971377 -694180 -653796 -465252 -635542 -730304 -917673 -661791 -905365 -910371 -756642 -338720 -928391 -397479 -534614 -234471 -160673 -581619 -383234 -834401 -686785 -995110 -475567 -103811 -152823 -702669 -622319 -616171 -447600 -289427 -122179 -733414 -385485 -546253 -111221 -229941 -523675 -915736 -395800 -552…
Output: 16546

Constraints:

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

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