CT48624

Sage's segments Frugal Pairs

MediumL5 · Recursion RenegadeAcceptance: 0.0%XP: 60

Before the gates of the spice bazaar of Saffronia close for winter, Sage must finish the segments 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 <= 2094; 1 <= a[i],k <= 1000.

Example 1:

Input: 1462 947 652 405 93 927 519 646 933 695 452 940 828 766 983 126 596 114 826 713 894 957 841 166 91 564 873 571 936 4 413 14 43 792 692 212 431 525 831 338 553 569 326 614 955 599 404 426 373 771 503 301 275 174 535 522 138 669 140 694 167 935 868 983 353 439 803 727 247 855 935 688 381 110 848 626 357 228 102 732 990 287 380 134 534 785 799 318 98 83 707 586 864 214 797 660 409 542 709 372 69 113 169 116 462 731 972 336 220 127 220 178 607 305 159 818 334 79 607 977 428 910 364 473 989 213 718 464 677 842 945 129 215 217 570 942 480 638 183 134 594 115 447 442 148 790 20 244 467 933 226 635 748 598 173 385 279 749 431 101 893 864 720 499 209 780 137 634 906 948 294 361 915 175 981 267 760 37 262 593 502 269 490 819 505 428 175 318 934 998 314 523 158 213 236 101 292 260 331 762 750 333 210…
Output: 465422

Example 2:

Input: 1158 647 567 368 477 551 179 663 588 179 322 24 32 41 443 660 81 859 238 676 561 830 663 865 77 747 751 609 38 624 716 721 950 24 407 975 13 463 434 443 552 763 192 315 124 714 762 787 667 623 205 988 182 891 184 478 34 753 162 966 910 497 343 757 729 142 527 176 109 149 862 433 149 217 317 499 466 681 207 207 596 240 390 435 394 110 765 913 769 887 419 106 513 863 469 911 689 424 529 235 57 249 112 682 9 426 890 564 59 354 245 264 438 404 634 675 763 499 89 126 803 114 327 767 118 463 383 121 725 88 434 299 583 969 12 821 989 788 909 464 93 944 63 513 116 369 786 817 871 530 660 471 628 534 232 161 419 888 694 177 912 751 123 391 546 739 72 628 876 628 723 520 159 25 570 38 385 173 812 401 230 172 297 884 232 417 79 203 79 97 743 806 593 196 302 748 144 260 755 233 153 569 583 164 323 933…
Output: 150032

Example 3:

Input: 840 329 98 237 496 691 659 614 853 959 622 749 944 251 473 444 252 133 136 225 78 104 112 560 943 987 421 973 557 451 539 53 555 894 797 365 359 790 236 546 560 290 292 278 832 395 619 833 390 970 108 166 740 229 384 849 301 815 956 352 565 94 290 617 712 525 711 701 446 593 966 921 668 770 313 976 836 389 375 854 898 907 789 962 330 989 821 379 520 457 129 701 197 499 380 683 61 331 477 656 855 638 768 950 393 31 259 26 956 617 815 323 114 426 863 805 789 157 72 888 980 319 410 235 118 397 575 849 242 708 72 470 508 935 180 490 320 294 998 890 579 687 403 133 600 711 596 529 761 484 227 777 121 606 247 164 299 11 134 748 710 203 220 624 437 941 545 46 105 726 678 337 776 656 262 904 650 775 282 823 870 28 298 350 95 862 847 80 386 606 774 33 159 190 319 100 571 294 762 526 991 99 720 45 3…
Output: 15699

Constraints:

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

Loading...
Test Cases:No test cases
No test cases available.
Sage's segments Frugal Pairs - MEDIUM Coding Problem | CodeTikki