CT42925

The Deepwater Frugal Pairs

MediumL5 · Recursion RenegadeAcceptance: 0.0%XP: 60

Zephyr inherited the ropewalk at the fjord village of Deepwater along with its curious bookkeeping system for scrolls. Time to make sense of it. 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 <= 2740; 1 <= a[i],k <= 1000000.

Example 1:

Input: 2006 691 97964 597653 974929 307554 994884 148009 781848 639168 805151 503455 881650 517564 143024 325721 443016 336003 792218 63808 905437 159311 573908 970426 878138 674965 203265 947184 787585 202211 249057 951198 805642 336838 512078 18287 288403 828854 303151 569161 905326 526328 279694 101369 563030 599419 756391 773919 123791 511253 810915 307537 5525 248724 564697 668342 113992 796212 702146 4671 318258 486263 155807 139793 711297 170996 915687 114197 221541 372035 384551 768448 754563 75483 101560 582712 393420 795924 671010 819935 40869 629484 880114 936648 959812 262748 416196 947337 728588 412428 313341 157894 233992 348980 827757 429147 462862 448745 879715 290126 490640 406933 997309 786767 730153 995664 384375 428744 564753 577202 170017 757929 458488 270427 539073 582765 38…
Output: 0

Example 2:

Input: 1819 420974 342190 549427 86201 213589 907185 131137 48378 128967 355623 370760 342924 896751 848735 250417 375506 732659 471458 796741 846507 983061 723603 707029 692858 518411 290714 954374 758777 831669 864378 235989 100102 452023 185129 721506 285360 298674 786467 529741 531994 8081 655283 521805 507512 832342 572369 309530 917387 374562 327923 291026 385759 282020 422258 56646 208107 506417 43941 829037 397274 808242 835279 737216 154542 481399 549351 820207 452663 87684 746766 345225 244090 413680 573064 908011 466451 740382 525474 817942 116233 904729 142164 834746 367498 540990 16238 192467 856221 663024 280511 416462 277353 46941 968474 489996 425294 192971 71518 874521 374577 914836 203312 45730 673990 723172 700544 277114 129327 208780 571961 717174 341171 762042 124557 582155 6…
Output: 143634

Example 3:

Input: 1217 152202 575399 50866 111009 777904 159587 29716 763912 44404 935631 875712 768811 384332 991712 703929 991274 661514 628446 948690 130032 436709 596010 167524 168099 736515 524448 936146 445600 387682 252162 118161 870896 981647 954714 520432 626231 122955 322067 102586 692980 390554 943488 577962 239936 965783 863078 520560 482179 6804 715377 620419 431894 419960 368569 850526 460141 531328 954145 980092 980626 772393 540430 358582 325733 698828 424861 528516 242160 843139 808873 208394 738244 480918 370357 754992 936962 389083 397511 384635 924511 867264 291659 467635 936576 179482 123942 383855 611775 472378 375739 759574 563014 591398 415655 888522 757956 193949 588480 938757 515586 425654 513745 267247 43889 772339 629149 50191 154366 300596 943220 883181 125171 323665 155010 7085…
Output: 8673

Constraints:

2 <= n <= 2740; 1 <= a[i],k <= 1000000.

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