CT38901

Wasim and the Frugal Pairs

MediumL5 · Recursion RenegadeAcceptance: 0.0%XP: 60

Before the gates of the tulip beds of Bloomhaven close for winter, Wasim must finish the stretches ledger - one figure at a time. 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 <= 2744; 1 <= a[i],k <= 1000.

Example 1:

Input: 1440 1050 250 746 939 474 272 319 566 773 571 769 328 496 403 932 713 984 197 248 309 814 924 986 407 523 693 359 485 83 615 493 164 654 132 987 565 321 826 489 941 883 21 831 351 741 623 848 112 334 736 822 952 836 663 346 12 122 601 755 581 188 37 879 762 636 986 343 714 368 248 233 81 456 554 91 799 747 54 960 345 145 142 499 979 700 48 522 666 865 706 761 505 728 414 650 372 145 970 289 148 413 558 805 945 53 612 303 915 317 350 48 170 55 65 124 105 327 907 858 520 181 734 490 446 676 396 557 799 207 655 572 508 117 479 26 880 691 508 557 161 867 443 874 209 127 743 435 549 716 799 55 726 95 881 884 511 744 469 226 682 388 26 784 656 280 577 131 897 7 843 993 226 510 480 691 433 80 957 721 398 618 661 849 387 944 596 674 557 375 166 501 558 649 974 42 665 250 865 561 377 307 659 529 33…
Output: 544230

Example 2:

Input: 147 1917 690 21 277 31 846 211 608 247 627 592 907 500 101 914 50 695 915 795 626 749 272 800 86 124 699 775 474 651 810 826 586 927 228 707 716 580 124 47 440 459 535 470 886 338 82 128 659 779 694 532 918 979 620 435 813 1000 725 531 39 568 789 54 440 592 961 88 73 82 724 240 671 744 993 772 731 449 558 47 936 490 632 737 229 439 955 485 317 401 652 111 687 528 737 558 345 933 555 938 448 776 860 334 398 446 735 354 974 38 52 510 17 324 722 410 299 491 911 202 138 538 340 423 321 121 179 79 165 173 306 746 190 302 666 275 394 352 183 110 437 217 987 137 949 979 385 631 63
Output: 10686

Example 3:

Input: 1031 976 687 938 789 740 774 455 937 634 448 758 960 553 774 524 15 341 454 626 307 843 626 697 898 681 77 832 798 483 985 736 430 278 649 629 116 172 879 951 502 135 599 522 71 509 381 449 539 808 796 615 853 267 803 715 756 435 730 559 868 867 664 672 138 301 973 712 179 442 481 931 247 750 117 76 255 137 624 876 539 579 265 962 952 467 501 384 135 701 162 370 894 27 348 275 796 117 185 735 933 999 320 464 587 499 984 376 82 594 414 179 96 95 594 543 714 657 358 436 586 90 971 722 141 743 813 209 342 896 65 62 183 393 860 401 264 166 70 84 230 410 793 229 157 833 408 712 37 332 917 279 951 972 579 772 655 290 943 556 753 854 791 291 463 163 616 338 2 98 947 126 439 791 968 61 388 745 326 865 289 105 687 376 226 322 556 224 104 807 412 879 976 987 105 544 418 277 968 962 92 796 335 584 11…
Output: 240239

Constraints:

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

Loading...
Test Cases:No test cases
No test cases available.
Wasim and the Frugal Pairs - MEDIUM Coding Problem | CodeTikki