CT51029

The Frugal Pairs of Ashfall

MediumL5 · Recursion RenegadeAcceptance: 0.0%XP: 60

Deep in the ember dunes of Ashfall, Rohan studies rows of scrolls entries. One clean number will settle the guild's oldest argument. 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 <= 3804; -1000000 <= a[i],k <= 1000000000.

Example 1:

Input: 1239 766191795 551701430 382886184 160523077 435017125 810089061 873809103 342068567 555074548 391070637 358252201 519037917 820612032 791512723 426935464 933048328 201298086 161214732 786643622 952535086 505771829 666659313 320798298 561531119 351695815 788089048 543122990 427851774 248843859 363834268 536997071 279555284 41587503 797868089 473791628 596955537 609487742 230052941 41763078 598285034 174080966 849066097 362072042 153071679 273022717 201926385 208779735 538548562 343630111 279643127 703229485 166157388 34514867 34532649 71411572 760976 206136549 271152387 600870887 322085103 478655913 525791078 505980656 651201437 554332944 358925091 344716966 513588228 645739192 215796557 891295875 505323257 835447035 606932204 614999836 994332303 978462554 472426367 934988251 759088049 340…
Output: 235388

Example 2:

Input: 1163 194853665 560392239 601737332 723279203 568529901 944120067 690771621 766309570 20171956 385565316 454004908 851126789 992012835 455884170 742451794 62305472 850357503 441204637 342214490 252858242 616915448 80465117 625869532 465049077 726032840 130742626 969380995 406086010 765162548 543151493 254699053 113983686 544141859 382678044 35885547 888436767 72647382 229573323 518416432 478141563 956636969 373216224 60477035 969528367 225387874 237982134 50195583 871185916 206536552 110173995 226075501 106070782 925211222 629683984 690692865 345184270 159056056 461894115 792999737 145050146 663404438 671994115 669938447 944512397 521793228 271132190 496759038 403638487 86821004 467700532 777596313 766078566 453511547 386615369 476184624 404959122 689541674 684674204 862066079 759632359 746…
Output: 14030

Example 3:

Input: 1043 638434422 736869218 361847412 340931977 251175939 786113012 19101545 882149626 887588157 682657363 67653780 934093718 333465729 149035214 633327351 714580352 806843789 116500344 751222350 135700782 792808002 850308097 343560659 667618017 391675699 966526596 645536497 354878966 437923518 333183002 6351876 252615037 509048807 57552202 830241326 913578118 379016911 280003763 571322215 314122554 80384796 776211664 913483619 659250782 490916518 65926496 30895737 658163767 782741227 912137799 567870566 477853813 668725851 98034928 739812923 672756703 527707884 3390426 943422154 404342155 77481251 261684254 565018157 903912884 85995445 342134541 633511302 12724610 294514551 873718384 236820148 105201093 174518304 510385228 138260547 799821188 342692752 340614528 491351947 760966854 68450510 …
Output: 116681

Constraints:

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

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