CT31272

The ribbons Frugal Pairs Puzzle

MediumL4 · Loop LordAcceptance: 0.0%XP: 35

At the caldera rim of Firewatch, Aldo records each ribbons in a worn leather ledger. The guild wants answers, not guesses. 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 <= 1558; 0 <= a[i],k <= 1000.

Example 1:

Input: 1369 1046 654 460 143 123 184 872 522 851 601 860 94 528 87 388 639 91 422 631 108 919 612 716 806 927 837 627 535 445 173 849 22 641 666 344 437 11 512 222 447 320 821 746 337 492 222 629 632 118 543 737 81 885 951 55 164 623 830 495 961 951 923 824 363 765 238 893 391 630 839 627 665 883 824 686 13 154 41 170 829 818 882 474 808 85 926 86 571 401 17 507 846 179 640 894 143 646 507 38 160 178 327 925 829 863 817 77 824 927 514 547 793 449 609 907 1 461 181 422 551 426 640 411 932 669 246 711 402 184 327 556 652 981 683 125 796 474 691 69 597 408 519 128 12 690 939 933 250 315 155 882 588 348 281 384 0 479 212 700 264 638 700 576 155 622 347 208 358 859 425 264 318 137 281 76 890 166 596 330 817 90 364 467 717 68 763 278 790 178 725 962 939 785 127 499 829 825 82 190 307 510 499 370 697 68…
Output: 518156

Example 2:

Input: 897 1842 774 510 665 755 793 445 942 914 749 102 959 960 650 436 278 164 568 994 442 373 714 504 980 881 791 657 469 993 199 993 457 579 227 684 925 548 940 714 20 138 215 17 346 793 650 403 530 691 473 579 38 89 143 965 677 919 115 729 0 98 963 921 53 115 658 203 127 544 912 52 413 31 220 480 864 579 510 976 108 336 582 636 605 285 253 883 856 496 584 475 93 351 174 775 162 931 495 723 508 628 774 851 118 94 374 183 157 179 697 784 908 197 667 727 868 342 613 79 74 292 514 489 6 46 923 952 973 226 473 533 154 803 963 42 195 91 212 247 107 365 176 93 822 991 178 715 685 456 7 707 531 2 236 887 954 156 159 136 799 593 282 402 262 216 633 643 49 648 768 426 241 969 402 903 306 122 327 294 597 460 253 956 765 519 661 33 393 680 727 450 381 690 889 481 640 733 878 217 108 529 108 160 231 660 4…
Output: 397566

Example 3:

Input: 132 264 84 690 931 159 675 50 287 247 130 934 859 678 798 968 793 45 465 274 429 993 816 836 312 660 96 692 348 615 89 806 974 224 632 274 984 732 396 652 661 869 132 780 490 468 992 419 628 65 498 217 123 94 778 533 862 700 463 435 900 882 521 883 268 354 140 288 181 292 733 462 323 543 872 465 680 805 90 979 839 817 616 909 99 372 837 269 479 883 819 16 218 381 791 419 379 403 328 757 935 383 170 242 66 416 499 825 193 100 68 737 565 675 872 22 753 588 19 285 221 271 877 241 378 801 875 707 642 695 621 337 927 298
Output: 233

Constraints:

2 <= n <= 1558; 0 <= a[i],k <= 1000.

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