CT50256

The Frugal Pairs at Applerun

MediumL5 · Recursion RenegadeAcceptance: 0.0%XP: 60

The harbor bell rings at the orchard lands of Applerun; Peddler weighs the day's scrolls manifests and starts the calculations. 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 <= 2514; 0 <= a[i],k <= 1000.

Example 1:

Input: 574 264 935 927 408 836 154 909 240 738 218 214 668 956 92 441 480 153 652 446 859 998 996 959 362 825 654 982 408 475 848 180 488 648 362 352 239 436 935 318 95 432 789 490 900 481 535 378 926 606 861 745 801 861 131 300 539 196 890 343 557 157 538 846 881 345 935 210 681 552 609 623 813 21 262 158 151 325 34 527 239 189 700 463 85 985 896 694 329 318 666 312 661 536 237 743 209 428 527 523 882 888 642 12 74 46 771 46 976 900 381 596 994 22 190 218 361 805 835 73 167 486 46 458 373 813 526 344 980 886 610 833 819 605 549 405 845 825 1 41 264 350 241 590 346 419 567 957 267 591 940 644 482 172 659 29 517 642 815 352 132 222 223 901 180 445 778 70 69 403 182 480 696 109 980 375 690 230 506 902 433 132 477 151 903 895 135 89 227 774 82 162 932 981 477 339 321 450 843 731 885 57 843 850 451 1…
Output: 6188

Example 2:

Input: 164 1932 970 123 794 356 668 75 556 86 636 4 752 692 195 682 698 65 260 150 887 546 273 993 561 872 960 827 7 55 743 351 96 722 160 249 518 741 348 733 97 888 739 513 924 468 694 620 995 680 75 711 69 668 13 733 925 646 319 602 968 859 162 528 305 226 441 914 860 638 246 14 335 986 394 213 597 1000 267 155 423 804 476 332 608 363 524 895 625 754 684 780 505 643 289 658 137 1000 845 994 71 44 781 381 889 853 689 45 491 397 579 346 433 487 234 375 485 781 359 386 467 134 982 661 343 313 364 10 874 286 298 52 248 291 387 844 971 482 361 370 830 379 637 60 38 917 188 927 692 315 826 726 41 554 870 211 914 940 981 403 637 459 342 412 908 11
Output: 13298

Example 3:

Input: 1195 1473 949 958 491 208 903 136 483 556 227 16 495 95 806 995 454 807 639 160 10 858 707 856 199 489 54 17 227 563 479 884 550 553 407 599 273 817 750 357 584 400 971 121 599 124 689 943 921 91 1 810 792 933 369 546 232 506 433 77 998 371 890 860 7 62 430 531 25 74 155 76 397 199 703 719 226 814 278 605 985 532 851 430 584 805 238 574 913 704 402 895 693 717 29 841 179 370 723 620 712 749 311 68 779 934 771 729 160 196 612 570 218 659 437 446 358 15 327 924 159 92 690 21 175 401 585 224 260 508 7 975 158 213 843 871 559 210 757 846 69 950 32 938 687 482 21 975 559 789 927 305 364 774 325 168 58 309 187 637 244 210 247 921 812 349 776 567 803 114 172 155 609 17 532 514 422 377 159 999 477 923 630 740 706 498 826 549 593 136 482 759 484 664 854 732 750 163 732 683 109 29 656 971 91 300 696…
Output: 619512

Constraints:

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

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