CT51998

Rhys and the Brass segments

MediumL5 · Recursion RenegadeAcceptance: 0.0%XP: 60

Caravans arrive at the honey farms of Buzzwell with crates of segments, and Rhys the factor must account for every last one. 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 <= 1051; 0 <= a[i],k <= 1000000000.

Example 1:

Input: 457 1176246078 106998315 564514053 366345843 514510256 326288365 481570935 993651731 398265818 573381792 193084633 478285065 235798002 105873463 814587450 72877060 650554721 767252404 676129895 402258080 392349175 436692511 511233231 168440580 819037259 928147021 586280588 901830459 210622111 22768160 976137790 64057642 804144805 979058047 40508290 931624040 566493564 114738489 123867030 56628288 747954245 114214193 687157024 982498277 137472200 725667282 223609394 238509658 843893745 278954253 682745312 176670468 683016958 822956558 989699396 618131571 937978413 655466802 85398031 26308629 406786075 364803451 846217275 335760265 388473509 593763533 426356734 798855064 581259773 459545245 975324792 112957928 695256866 80093195 932081384 289904299 351341383 924483474 502246702 678540755 122…
Output: 66915

Example 2:

Input: 630 1399616840 328734446 152625379 600143054 794318865 183853368 427952707 956500660 801243101 27079509 442814458 365354733 5733177 899366572 658993757 457884477 2496945 337092085 6080213 222320417 255987543 709364394 33065425 376230097 730457598 260673334 651526697 560992749 914518545 805982640 833989413 66220436 260704708 101673273 276166824 516598119 599783209 648947401 673361709 9997095 891364691 622361542 505116786 114775941 83692949 890674146 910834266 384523637 259982533 511019934 645366278 117585655 413343165 104920767 977985922 975484551 444044 67085596 607841617 717234346 426405864 251652588 401532605 549152343 556586362 289299067 313879419 350997996 226999029 222076607 794009385 16789662 356130179 5115440 156703124 902565461 337195991 72907962 75281736 384087688 492844304 362825…
Output: 162477

Example 3:

Input: 189 749040024 579558763 506418907 573826003 410071139 293505505 23562980 637813896 796227433 279439761 719860539 466086599 906450700 604866086 72358889 246520474 429590864 168913894 546177826 686246873 787711955 373337651 248301465 531447682 566527885 242688228 124114627 385014018 619141549 199438568 491383766 367364661 212101643 983299343 768897735 501224334 87751382 115448571 906866451 918145346 644972026 924009803 664857456 466300223 664690743 644398079 83871906 113068400 278389424 354032343 155989598 156207502 23602981 692729326 656019688 169420337 831139770 310967650 359502962 545931134 864053780 368681248 965371468 593522664 906700361 701169113 339207366 453771738 912805040 461904984 271043941 65549993 862515276 533159811 823815461 437018727 60232450 230695871 499248652 883601623 425…
Output: 5224

Constraints:

2 <= n <= 1051; 0 <= a[i],k <= 1000000000.

Loading...
Test Cases:No test cases
No test cases available.
Rhys and the Brass segments - MEDIUM Coding Problem | CodeTikki