CT33852

The ribbons at Leatherwick

MediumL4 · Loop LordAcceptance: 0.0%XP: 35

Surveyor runs the salt store at the tannery row of Leatherwick. Today the books show a list of ribbons, and the numbers must be worked out before sundown. 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 <= 3805; 1 <= a[i],k <= 1000.

Example 1:

Input: 1317 73 932 993 30 877 85 154 228 455 338 179 977 693 464 760 650 106 116 993 840 766 166 456 869 423 761 575 129 490 69 710 940 262 933 387 268 60 574 623 54 782 393 247 629 599 105 988 413 486 820 659 928 492 685 986 507 526 26 114 291 781 514 261 883 730 197 365 649 305 845 313 233 506 926 279 940 314 541 517 222 449 198 960 304 161 759 8 974 989 156 84 3 705 517 401 708 212 161 207 393 877 530 850 194 191 935 416 874 330 556 38 537 656 880 265 832 688 647 214 96 13 260 496 349 571 786 930 61 372 12 220 297 850 294 820 245 25 75 834 561 809 157 415 950 474 549 446 368 219 7 382 79 20 563 59 256 876 43 677 187 989 438 491 185 664 643 868 619 638 8 495 935 829 179 98 121 478 254 737 7 486 503 926 816 49 967 230 690 280 938 847 744 606 238 802 774 997 186 64 259 111 295 925 468 868 273 863…
Output: 1754

Example 2:

Input: 2124 424 119 597 680 417 145 786 280 539 464 253 669 119 770 992 69 693 944 677 97 47 313 784 728 357 216 302 339 893 416 473 677 253 119 327 429 993 503 480 182 5 818 190 869 700 640 436 86 823 556 491 83 489 708 515 499 915 995 175 70 11 980 462 825 979 644 547 865 968 233 682 188 913 391 785 998 100 355 926 92 707 975 372 315 314 155 328 695 47 37 846 649 17 506 854 859 408 349 504 877 64 627 604 405 375 855 315 554 852 565 547 828 753 732 830 616 203 896 684 666 686 712 540 569 920 746 730 201 38 686 164 982 654 635 233 494 494 513 909 639 538 730 768 113 369 768 96 262 234 696 753 823 532 823 304 729 162 191 639 253 850 13 848 298 49 188 61 703 415 59 761 123 827 174 313 781 22 417 319 5 115 935 178 220 939 946 92 384 954 197 287 376 878 817 216 602 336 842 539 163 975 959 827 319 990…
Output: 198286

Example 3:

Input: 2962 1612 353 525 526 800 667 5 460 558 806 621 297 864 809 424 266 527 146 70 19 166 980 486 66 61 620 694 556 10 107 343 419 962 513 922 557 110 912 959 865 338 457 312 329 346 123 222 217 153 465 917 734 178 935 3 29 583 158 838 765 971 884 728 61 858 254 628 410 656 42 871 227 764 601 60 853 596 601 373 317 652 63 860 733 691 445 149 770 752 906 428 643 95 179 303 703 2 783 648 123 985 143 234 42 303 369 722 981 935 16 991 662 18 451 998 772 438 706 572 507 781 327 564 963 19 826 644 731 772 912 271 671 664 166 140 698 406 638 937 838 391 716 358 558 822 430 442 382 793 975 961 531 708 730 306 405 4 432 858 9 916 245 417 599 643 239 388 169 58 586 906 370 271 269 926 327 242 510 957 423 528 588 381 977 893 176 177 47 722 905 249 511 718 715 964 987 155 468 77 567 43 390 163 289 268 293…
Output: 4052017

Constraints:

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

Loading...
Test Cases:No test cases
No test cases available.
The ribbons at Leatherwick - MEDIUM Coding Problem | CodeTikki