CT33931

The Zigzag windows of Jarl

MediumL4 · Loop LordAcceptance: 0.0%XP: 35

Jarl found an old ledger of windows in the brewery attic at the willow walks of Reedmarsh. The margin notes pose a precise question. 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 <= 2508; -1000000 <= a[i],k <= 1000000.

Example 1:

Input: 1808 935293 -234544 -238721 408003 -368109 -110678 713129 -452081 -29668 -355747 -162466 -98002 -706083 536512 433832 884102 386698 11608 225233 -294771 195764 926002 790008 -857285 -996905 330170 583380 432710 1628 696314 403136 975257 892388 116911 -854955 50421 529304 -99256 298883 -557392 -34642 -266989 -946749 646976 -680868 -797593 265565 884100 181367 -679450 190248 473651 -184278 567008 -751318 363247 208700 -108009 -985025 -209910 300636 -608318 472818 212298 323609 173398 -258810 108991 34826 896524 -289463 971135 355313 729255 799334 318560 -190157 -36929 -47100 -231194 665084 -745465 333683 -570946 -524171 666993 456331 -175880 -355346 -707847 433894 -285310 811477 -885882 -150645 -722798 106233 153207 955175 273418 451559 33884 351867 353439 233480 446270 -816433 -749965 -7369…
Output: 1391536

Example 2:

Input: 1077 1033013 -903440 474053 119899 608927 -243225 870436 -364092 -229397 53755 811414 -679864 -951941 -414016 -295528 755421 -169414 688628 -360495 -233483 369018 -351269 728364 972754 -882651 976611 125815 519128 823732 -221758 560892 141631 802739 -531711 -451013 -20960 -728563 -350613 -813279 -247415 -980228 -689365 118434 -577144 504413 -538661 685319 35431 -768630 63433 495077 -755999 292023 361378 293453 522539 319926 666703 -798489 -337224 -639623 -506133 424487 -123404 78530 -674681 200837 -713230 40845 648048 24084 -976151 -690081 -884202 499286 -186409 107462 -238253 484365 -499143 -835539 -863902 -831781 -298248 395255 406016 339351 -806436 807556 359230 969488 452912 376148 -868415 338417 -439512 867111 -449214 311049 -489399 -560049 -830925 -915710 368366 -120726 -526626 -8830…
Output: 509842

Example 3:

Input: 1390 -982420 -299690 9659 -815276 823324 -90741 536678 -812850 954631 646826 -499447 -259965 -686516 439104 696754 -512931 -426687 611865 -103095 783932 -35109 -603499 802685 462328 -603400 52188 138314 648764 -601135 -449946 -477945 189142 -740530 -794162 -777302 931957 892831 -566284 -916122 -769331 -335822 414969 553508 -983554 778557 -443510 -638989 -87535 319841 -266128 241166 -334543 986592 -657317 -573377 -56198 736263 460973 227499 392726 -182661 -700499 378201 741551 615281 650522 108176 -234751 59261 -329483 -639702 -561101 830688 -2221 -340779 -557059 -100393 256222 -577439 960138 -258119 -577729 817028 510197 -572438 -477025 -554362 -628427 -699053 68728 -700581 -173628 -345853 -611564 124584 -293175 74388 -636213 458103 -745718 -384365 -247729 -92762 -531022 -909868 -241945 38…
Output: 131207

Constraints:

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

Loading...
Test Cases:No test cases
No test cases available.
The Zigzag windows of Jarl - MEDIUM Coding Problem | CodeTikki