CT48885

The Frugal Pairs at Willowford

MediumL5 · Recursion RenegadeAcceptance: 0.0%XP: 60

The quartermaster Finn has been asked to forecast next month's demand. On the desk lies a long table of scrolls readings. 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 <= 3345; 1 <= a[i],k <= 1000000000.

Example 1:

Input: 2113 1330423991 991955305 220950009 310832689 605988682 334832050 266595306 31498404 346514231 537936974 112758737 458942047 990748761 143854356 929228591 704826730 369610716 80569983 994269078 953434906 601743537 598173819 434366425 579926088 489946841 984366819 427804865 324070285 86415891 712639202 868349613 238440169 420114912 687620181 593182211 780490534 3391618 945517585 18458769 818890679 215282134 401461481 404618149 209964255 433458720 603394032 158014615 132013226 700469583 608402261 478998469 87164634 449864319 977829543 755022912 929179227 663973556 912464616 691389257 54037231 49744184 892315393 893477620 652552248 292643685 54497149 86831017 183948660 18785619 629813265 446048508 338530628 533350761 731248591 310277937 173195698 123739552 487798204 255837405 771654401 372061…
Output: 1734503

Example 2:

Input: 2218 327226260 186563034 606388477 484240083 659860137 618148383 805781870 486479100 137092502 434862224 269086470 722199615 864132966 244580042 791130689 600878219 472012291 970544649 75141807 637248996 586099129 297670760 131347934 488142434 858180761 117133418 157189585 356775224 152412469 280990479 914071485 162396433 557020424 15477650 254196887 171627041 199717625 876110199 151594822 775817871 142849844 599394915 79748989 262477556 812773763 654740012 605789408 148881481 740087460 279367236 589927444 430974300 520567361 779486256 287191602 962782720 517445909 850476629 978033431 962936403 803979010 915359942 502111360 168714474 531757301 790248225 331700713 13621057 21908475 123138029 125083931 933554434 169013989 6188470 391515433 926372906 697751962 214798393 206304202 302942161 66…
Output: 137708

Example 3:

Input: 2395 1708512188 713027912 96699646 906315205 378834764 958169199 821571311 12679163 591986554 227363544 597572696 408102578 688608474 735152290 310358151 333140950 360130823 157640889 967544632 563443172 939042657 379718349 372694472 902577279 511269175 829250048 138527081 786406637 123925973 942206715 145427321 42122819 456812043 19960521 774399003 136332176 19812415 217328104 218059806 523842350 666248037 756445312 79459019 289563426 580014709 21626469 669983765 483964511 268245245 839505041 123778970 500774175 397389916 464735923 170230602 326330158 884065843 158677535 182541273 310587013 730419827 757820154 15220901 78643471 700871158 3656099 399156387 362223913 784676754 515473954 232615950 307821055 510307745 423458485 77941092 763924908 508320489 683730850 704149472 486707895 473094…
Output: 2761386

Constraints:

2 <= n <= 3345; 1 <= a[i],k <= 1000000000.

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