CT40244

Nina's Ledger of ribbons

MediumL5 · Recursion RenegadeAcceptance: 0.0%XP: 60

At the old quarter of Brasshaven, Nina 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 <= 1906; 1 <= a[i],k <= 1000.

Example 1:

Input: 1172 1743 238 459 837 810 208 400 335 350 678 993 829 581 397 148 712 409 982 972 924 139 159 548 991 781 799 464 861 311 404 180 186 679 715 889 381 921 371 759 444 58 897 352 153 834 1 392 307 919 210 304 177 166 302 221 664 964 462 280 487 657 711 734 992 413 750 146 501 992 915 177 274 910 705 439 645 362 585 880 532 374 408 842 630 158 293 250 830 108 730 216 368 317 43 775 312 247 607 127 169 377 756 801 325 553 655 778 389 867 171 501 330 322 497 396 665 416 44 598 508 217 704 200 565 849 296 51 325 459 302 291 593 546 941 251 177 70 220 600 745 475 278 32 531 368 8 541 598 428 866 926 734 488 259 791 578 57 856 995 752 390 197 578 946 734 797 316 369 436 221 727 564 180 846 563 659 364 392 471 628 116 298 398 443 800 364 624 347 675 445 164 177 564 611 580 263 954 542 724 986 613 3…
Output: 663391

Example 2:

Input: 779 300 889 256 482 562 582 133 486 661 298 324 996 191 540 407 400 645 889 390 284 66 645 601 391 359 811 604 596 780 942 50 197 256 389 939 129 286 1 564 414 789 167 290 42 893 3 546 373 756 283 536 480 631 733 723 142 267 829 861 998 780 746 893 612 173 888 88 167 251 354 294 256 577 865 445 487 678 408 554 520 767 720 197 358 981 847 973 591 851 714 544 133 974 781 745 369 775 683 56 530 161 192 54 40 782 845 574 447 901 810 769 998 589 712 620 419 216 924 954 804 807 258 700 129 308 397 802 85 678 469 594 381 367 977 277 828 170 465 497 852 97 444 672 942 977 41 783 270 190 680 924 46 38 969 292 655 168 742 248 553 942 702 849 915 747 692 587 755 192 825 998 940 452 165 803 631 559 866 122 598 44 479 943 44 335 168 651 13 939 152 103 826 432 111 936 629 581 742 867 545 907 791 843 797…
Output: 12228

Example 3:

Input: 1535 1784 932 36 950 156 662 925 844 225 842 1 806 199 444 131 166 930 284 852 10 669 94 833 213 717 594 949 431 350 372 336 613 746 274 532 380 199 643 520 648 424 547 217 212 913 12 685 765 410 662 29 455 84 337 865 104 415 370 510 918 962 40 181 391 763 164 246 982 203 121 365 550 831 382 903 412 600 388 221 432 71 372 665 867 708 825 305 988 688 194 236 154 484 878 429 85 681 427 627 903 190 986 912 986 708 20 948 14 456 399 300 211 848 233 712 522 418 655 572 909 947 309 903 856 814 611 197 871 380 609 378 549 523 604 8 178 567 763 273 232 601 70 279 948 519 796 157 953 223 891 819 888 62 333 529 152 2 15 773 3 137 263 943 552 724 811 44 249 781 454 712 739 946 305 144 280 596 236 912 922 994 701 343 365 582 388 499 817 30 702 188 160 579 429 731 437 480 442 471 665 270 483 356 79 7 6…
Output: 1142700

Constraints:

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

Loading...
Test Cases:No test cases
No test cases available.
Nina's Ledger of ribbons - MEDIUM Coding Problem | CodeTikki