CT45734

Last segments of Rosa

MediumL5 · Recursion RenegadeAcceptance: 0.0%XP: 60

It is audit day at the fjord village of Deepwater. Rosa spreads the segments records across the table and picks up a sharp pencil. 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 <= 1603; -1000000 <= a[i],k <= 1000.

Example 1:

Input: 1467 -97055 -860856 -652407 -778850 -613042 -68829 -561748 -656223 -302336 -631518 -291615 -11068 -153535 -305666 -20096 -244593 -910343 -103142 -182957 -373890 -599059 -846509 -245832 -348809 -464098 -178821 -992942 -789678 -728065 -283435 -18893 -550869 -238269 -754155 -748993 -112917 -173572 -474637 -49759 -753646 -642972 -504678 -858356 -1711 -574622 -321281 -819050 -621733 -730214 -953478 -155836 -893489 -785074 -566869 -732176 -874136 -454518 -698529 -719531 -345393 -829745 -367166 -451164 -920880 -441180 -731652 -491269 -794825 -264927 -524049 -325044 -484847 -108913 -86133 -220596 -624808 -239075 -80493 -323501 -494725 -425462 -718585 -440312 -952233 -829118 -867662 -44117 -93786 -921082 -825412 -838986 -145436 -518449 -270301 -910037 -574486 -268442 -449018 -796503 -484660 -275808…
Output: 1069546

Example 2:

Input: 541 -950554 -273777 -877609 -200989 -818588 -508500 -757935 -978366 -587704 -676977 -9368 -403034 -663588 -860382 -571477 -229411 -122017 -172847 -135677 -799335 -562642 -615807 -113068 -801069 -264858 -622407 -406511 -416296 -525310 -376484 -984452 -685702 -5369 -47126 -666126 -101578 -838844 -189792 -539031 -513431 -206475 -667359 -913447 -676967 -468582 -888182 -126846 -362035 -668697 -907961 -167187 -39415 -102945 -487236 -620362 -555080 -999558 -447380 -996292 -695910 -507563 -65548 -773252 -636118 -863045 -720879 -156111 -272851 -74406 -373625 -568912 -299874 -93441 -18506 -637510 -110699 -861028 -49238 -401721 -157816 -597698 -371586 -814309 -429391 -937920 -789018 -330695 -132591 -129883 -742187 -445877 -472382 -821078 -962146 -163098 -555585 -387254 -364845 -101649 -650474 -72324 …
Output: 75599

Example 3:

Input: 857 -769010 -463668 -551218 -318721 -720660 -979033 -869101 -798231 -88285 -644496 -757518 -72335 -905402 -556781 -68927 -792624 -646447 -665806 -79105 -670643 -773027 -142571 -133180 -635784 -346941 -863356 -676594 -645169 -455154 -161039 -962035 -166389 -117909 -910812 -882776 -405781 -24767 -117617 -927904 -790177 -846995 -739123 -656508 -461418 -70725 -837648 -250647 -141053 -905555 -750679 -7681 -137826 -473164 -773682 -951926 -509048 -470680 -618385 -957108 -303613 -157546 -305663 -486238 -526603 -911548 -158763 -370164 -514198 -366531 -613167 -719593 -313326 -122825 -202700 -44184 -742454 -771501 -778075 -568889 -854145 -785401 -948617 -232674 -427931 -336937 -644686 -372092 -171807 -190233 -979528 -754028 -725673 -779711 -851981 -45349 -324458 -839565 -217622 -164484 -864501 -95219…
Output: 259352

Constraints:

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

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