CT35713

The Frugal Pairs of the Granite panels

MediumL5 · Recursion RenegadeAcceptance: 0.0%XP: 60

Mira runs the kiln at the forest village of Briarthorn. Today the books show a list of panels, 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 <= 3445; -1000000 <= a[i],k <= 1000000.

Example 1:

Input: 529 610185 998097 87476 -485660 -91477 -89882 -290418 -436743 542255 -284731 2197 -753746 368111 -162032 -479586 341800 208208 211452 651467 716530 -490248 -665832 -849126 -506406 146163 -603669 854082 -520769 -171251 588118 -211782 -609711 735309 -606408 -299208 12086 611400 -95378 -827192 250194 -673744 170426 720017 -220991 -664867 969825 20651 816958 524498 -834980 650864 893156 -628638 -57095 -481161 -811461 298830 -515826 -941079 843144 294920 -659300 406398 -282616 -269552 -957709 220079 -269147 -447354 421081 -618078 88100 277064 145068 -420552 -391209 -243807 -957141 855469 920259 -847397 -813942 244834 -87248 861435 -616446 -465873 -310292 -142147 -963421 494754 -257942 294668 -186933 -582524 -874911 -62932 -734524 548804 -872386 508956 -921689 -297722 -942469 -567487 -703738 612…
Output: 109931

Example 2:

Input: 1200 1205596 -229925 -354446 422312 -577412 -697997 -888248 683172 91710 -44776 99817 617219 -366335 -492354 112467 95379 142072 -832083 640465 -256462 822394 -932021 -722039 36447 -405404 -794415 603201 -647215 114999 -794947 137133 -107106 997732 592290 -523218 -885588 345736 -465273 -980189 889733 783563 911510 -418300 -526222 371743 531504 -81709 -204139 203348 486427 -428784 -193735 956680 -410268 50288 -301071 -122437 -605841 610365 75843 -951683 465236 -19591 740554 -574062 636506 480229 131278 176294 23218 -28248 380593 -463157 -285301 -455631 468133 -650064 614490 50636 -103276 667973 818149 853323 976697 -798958 833304 -136188 -263273 662494 -538466 155008 -6810 573411 -518934 -481921 -830369 294919 838290 -544401 548847 715429 -851326 -869584 -415495 -600160 -35833 981007 -31055…
Output: 670855

Example 3:

Input: 1944 -951086 -239381 -117818 -183515 -750629 451239 -782074 510657 360595 -268601 368317 -438115 -561749 818954 -278495 -447675 501786 -275915 635831 -399211 945374 142414 -900798 26475 324721 406623 613673 616389 101986 -4914 -84284 -596908 536972 278551 437139 630968 156167 -578300 18959 937717 452169 407456 -142762 946914 -525844 -213244 444513 775203 -192371 241153 -174272 291155 -318726 -364675 395119 -706751 477304 79863 992810 -202626 15356 133994 660366 -228107 677286 -376122 218037 716196 -41974 -162052 -167308 295669 689234 -556873 714431 -438328 -697239 363415 -785276 -28993 -55526 -188548 -272842 826062 -475720 -202576 -973660 -725899 501752 -643284 -975541 -261177 -365150 -609465 106304 589663 -914609 -720764 357098 -853312 410844 -585356 302704 -574533 -677024 704410 -251816 …
Output: 259700

Constraints:

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

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