CT40597

Rhys's Amber ribbons

MediumL5 · Recursion RenegadeAcceptance: 0.0%XP: 60

Rhys found an old ledger of ribbons in the ferry office attic at the otter slides of Sleekwater. The margin notes pose a precise question. 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 <= 1418; 1 <= a[i],k <= 1000.

Example 1:

Input: 1177 350 282 792 90 158 222 621 61 66 756 352 262 398 814 15 843 528 932 275 629 681 210 564 155 222 501 268 536 127 333 312 157 768 85 926 930 951 219 2 943 26 466 759 962 233 993 940 601 742 560 768 723 528 112 329 575 218 777 30 707 71 838 730 605 278 897 635 135 259 555 35 754 386 595 154 627 410 424 811 179 317 461 957 798 667 342 45 904 456 297 128 298 825 373 652 273 602 260 84 740 377 877 779 776 469 186 156 652 750 448 670 108 663 69 259 263 628 831 773 266 879 77 444 681 142 606 337 488 180 125 382 696 824 182 997 602 672 527 373 704 37 800 987 519 312 922 167 174 745 706 613 109 674 716 478 248 759 381 552 974 286 182 425 795 198 648 876 285 210 966 511 199 153 358 29 580 933 585 502 61 685 464 455 113 866 133 132 301 517 621 791 955 614 198 394 317 12 370 324 638 725 198 269 22…
Output: 38111

Example 2:

Input: 1118 1612 437 198 628 694 200 558 239 192 252 287 800 80 434 16 471 116 973 229 884 791 731 672 12 462 367 978 1000 452 973 904 589 813 278 179 818 878 317 303 121 264 505 422 923 287 864 858 840 912 358 638 86 994 922 612 237 704 37 518 758 860 670 11 629 504 667 274 157 205 837 206 1 496 572 526 645 209 775 1000 842 133 804 450 576 971 9 258 328 691 92 508 478 304 203 626 352 677 14 174 292 922 134 663 582 359 260 999 178 498 343 547 432 895 787 685 958 659 688 590 277 429 786 226 567 283 90 840 381 411 810 758 870 406 716 355 90 370 620 818 639 538 688 422 859 866 774 232 943 467 790 141 643 305 856 418 965 515 754 805 527 64 612 520 235 48 296 97 185 610 37 762 112 273 125 659 92 182 511 998 273 585 329 661 972 243 512 437 950 439 471 906 951 761 220 986 466 532 838 710 970 45 590 238 …
Output: 572540

Example 3:

Input: 116 1286 386 242 134 439 250 80 485 205 618 18 380 945 129 250 235 226 353 421 554 128 69 316 652 987 622 335 189 955 339 944 368 680 217 358 765 369 399 311 41 601 729 53 894 971 930 726 296 316 474 97 385 976 255 186 451 824 761 61 92 929 180 794 540 117 213 499 663 452 288 633 593 978 4 596 468 340 942 588 579 780 866 941 383 516 362 521 771 678 680 754 45 31 231 607 604 245 842 587 122 632 761 417 636 559 409 488 225 829 629 850 620 765 423 160 126 388
Output: 5299

Constraints:

2 <= n <= 1418; 1 <= a[i],k <= 1000.

Loading...
Test Cases:No test cases
No test cases available.
Rhys's Amber ribbons - MEDIUM Coding Problem | CodeTikki