CT34745

The Frugal Pairs Beneath Reedmarsh

MediumL4 · Loop LordAcceptance: 0.0%XP: 35

Caravans arrive at the willow walks of Reedmarsh with crates of windows, and Arjun the quartermaster must account for every last one. 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 <= 2337; -1000000 <= a[i],k <= 1000000.

Example 1:

Input: 1545 207139 848167 343173 878828 86337 -193407 -57668 -995806 -11955 215158 866748 -907699 -795981 759456 -556572 -147190 -970841 -455896 -673366 434248 -464113 -316809 -307812 445868 -503785 -985338 -358406 223939 8647 491947 551718 362470 750387 769434 855219 262477 71065 -918927 643056 -951336 488105 316843 -156185 -927532 894008 596911 -177031 373702 842999 -825246 -622741 -87933 747846 558148 723059 -285022 965742 -622075 213313 -677771 -596902 198161 53742 -200345 642789 -672291 326125 -249387 158388 -344241 -506262 47021 -81002 896277 -916686 -732838 380553 365896 247293 340784 973439 -8227 -405563 136015 -960359 -401967 -184806 -256740 -465084 591482 -663605 763606 -589825 -323953 274663 960450 -255745 -488491 -417580 893622 251972 -904558 -947709 -679089 -611754 778291 37578 61145…
Output: 706133

Example 2:

Input: 2141 1197007 -884814 762464 -875493 -285962 -488742 696792 932963 209325 694345 4894 398153 680910 -928972 141400 -60565 -870400 307679 -988348 248859 130930 -744220 832141 934492 -701017 -530207 17871 102723 -704619 -752853 299988 93832 161236 -25931 -752071 -180502 -408067 -790177 155500 867727 149669 245626 -849721 749335 969498 700449 971223 515064 15329 -43366 -795768 -571753 401670 -391954 183612 -572695 154369 -394558 -951361 756196 220017 885828 205886 514843 -430098 19378 707408 -941966 843725 916260 474664 567006 -650327 -336332 -829649 496403 -748940 451172 -986682 -276199 -484341 928403 -826471 261764 -690243 207920 -454033 476717 -472333 56212 901931 796961 -642205 926841 382782 -351116 -910285 -535001 129085 -967389 983954 -313410 -262579 -769471 -70475 841242 -798723 -445641…
Output: 2114115

Example 3:

Input: 610 -819200 422692 568172 -492109 844301 142565 -71019 -317501 -79649 -12792 157318 -522985 144999 -993297 -846423 -737054 -668345 -521630 914559 -640894 337826 -974324 221339 -355626 -66106 -753144 788733 -894172 847280 34202 285345 -40917 426129 -362996 -359675 29100 -310146 930142 -695984 842738 -407456 -340441 321197 976665 173416 217837 525238 -894597 -505722 503203 -468093 -785192 -5394 71620 -259208 346481 229842 132483 797849 -82721 76473 -906288 -790120 -128755 875606 91597 -316705 -244961 676932 -696698 -266032 -212445 650869 419183 -447996 -924282 -219106 -186409 887812 -33381 -250367 -947882 472656 -992162 -795796 -248938 -63550 -321240 -120787 -281316 -396356 -159684 44416 -449519 -463949 953258 -239933 -426102 365167 -933765 -995539 21690 661880 -194570 542914 -816622 224577 …
Output: 34242

Constraints:

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

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