CT31416

Zoya's Violet ribbons

MediumL4 · Loop LordAcceptance: 0.0%XP: 35

Zoya the chronicler watches over the tannery row of Leatherwick's stores of ribbons. A careful computation stands between order and chaos. 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 <= 1041; -1000000 <= a[i],k <= 1000.

Example 1:

Input: 732 -355386 -229699 -920344 -637150 -479218 -751676 -466654 -541662 -768544 -119059 -173735 -656565 -520721 -290608 -426189 -906734 -391453 -106533 -172366 -509925 -289620 -607425 -558358 -446894 -558912 -814189 -212452 -886850 -974850 -751227 -323149 -443885 -656344 -178964 -538372 -280703 -700266 -229949 -41872 -979666 -294020 -664724 -144841 -150426 -716835 -211989 -521006 -294896 -732942 -233193 -885857 -302143 -941300 -364393 -142907 -185737 -546056 -139420 -20185 -965748 -490154 -586577 -737780 -241200 -179583 -298638 -616449 -9669 -347630 -732612 -602991 -467007 -49669 -375778 -686922 -131168 -24187 -540208 -950996 -73671 -466106 -308672 -143882 -524787 -812147 -517396 -625340 -838112 -364142 -716842 -723759 -338582 -639864 -970978 -338271 -871121 -914693 -994625 -991535 -887471 -39…
Output: 252220

Example 2:

Input: 884 -490851 -916174 -509336 -131906 -975637 -667600 -737164 -919938 -639671 -338229 -421100 -25630 -217861 -269738 -406632 -925872 -72849 -371315 -324002 -728254 -206325 -431100 -396501 -457735 -70640 -48645 -98623 -511002 -219294 -361345 -681791 -666448 -579727 -569244 -515258 -47269 -77612 -639838 -711873 -97735 -744654 -476603 -741404 -479118 -89643 -144138 -545973 -493569 -194523 -45817 -311645 -766073 -906835 -381940 -602356 -105939 -256571 -774791 -905116 -665562 -564193 -586013 -958154 -712483 -247497 -334654 -686822 -705723 -376343 -903823 -150262 -397303 -257769 -846284 -216129 -294780 -990131 -742536 -78674 -558073 -865351 -769403 -137087 -256719 -142856 -554169 -664090 -450840 -159504 -28347 -874405 -809913 -498821 -662594 -957091 -104502 -513620 -132055 -881286 -340318 -2189 -5…
Output: 344770

Example 3:

Input: 624 -198755 -593910 -901656 -732227 -192533 -594118 -8315 -393333 -405118 -950895 -138477 -827701 -936386 -958876 -526131 -633266 -232432 -299485 -756134 -274636 -871902 -270106 -846666 -982532 -179753 -57559 -52091 -127444 -67552 -751494 -587371 -723598 -885994 -979075 -543609 -710502 -556484 -551936 -319568 -981571 -437655 -810138 -337318 -507900 -163430 -339253 -3077 -562541 -37305 -400527 -710414 -266246 -853127 -320940 -166173 -262392 -188895 -209683 -733525 -855724 -795665 -397297 -89295 -219078 -456349 -882080 -51776 -472680 -282326 -794248 -942271 -485426 -109820 -886521 -792448 -674599 -300869 -791101 -269636 -486142 -387154 -533801 -612779 -26384 -840344 -224302 -624938 -119195 -413014 -798308 -475825 -334008 -297293 -599291 -961623 -794915 -930733 -207432 -197875 -704249 -939560…
Output: 191178

Constraints:

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

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