CT44298

The Peculiar Frugal Pairs

MediumL5 · Recursion RenegadeAcceptance: 0.0%XP: 60

Every season at the singing sands of Echo Dunes, someone must win the guild's seasonal contest. This year the task falls to Jace, armed only with the ribbons register. 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 <= 1424; 0 <= a[i],k <= 1000.

Example 1:

Input: 1154 1408 327 449 314 811 643 236 174 154 436 929 622 722 457 936 60 186 259 533 473 30 26 202 841 357 899 525 174 328 95 262 887 34 646 320 150 504 295 464 179 501 58 251 459 750 990 594 670 22 689 319 165 36 704 533 290 775 149 774 65 757 394 731 128 913 757 646 565 282 882 143 441 608 85 405 836 774 926 16 211 443 650 397 470 60 951 358 737 588 967 327 765 71 563 174 886 479 535 23 447 777 425 874 838 682 193 498 223 255 536 676 431 990 597 262 340 244 425 346 39 516 728 524 322 198 677 501 988 940 158 209 359 60 941 228 561 63 953 188 268 578 713 916 169 904 438 524 302 507 358 202 879 256 145 435 972 755 256 721 743 40 125 910 392 170 898 380 312 504 417 571 929 215 562 820 533 657 36 980 717 782 954 166 781 247 684 49 699 50 351 613 586 591 441 579 848 435 813 419 855 63 826 878 706 …
Output: 557328

Example 2:

Input: 1386 415 339 130 383 764 369 703 970 775 993 834 881 348 589 852 877 487 655 891 860 887 285 33 568 484 350 881 39 210 69 171 997 844 17 366 828 91 70 911 464 661 443 40 56 162 689 41 388 762 438 160 581 765 311 163 497 983 392 594 577 227 140 909 894 670 711 849 352 544 848 588 23 510 557 740 828 906 721 104 247 462 382 659 171 34 485 259 362 298 307 742 619 384 240 704 678 679 814 399 704 41 235 12 17 473 574 754 333 796 526 406 725 849 626 218 899 870 838 430 510 681 184 318 74 95 304 862 710 985 560 80 310 690 139 10 197 897 590 169 572 277 16 625 493 405 343 66 55 811 418 97 774 132 697 845 458 42 403 415 306 525 19 946 739 0 718 365 595 326 786 96 194 261 541 531 719 221 465 302 164 980 359 889 188 998 25 402 345 423 777 749 327 838 378 416 332 415 106 683 522 357 543 44 952 108 838 …
Output: 90427

Example 3:

Input: 130 383 937 978 53 83 673 675 314 895 991 485 219 341 460 772 798 784 949 35 395 935 200 404 551 59 141 318 506 678 23 646 415 263 599 158 222 538 983 880 906 807 843 325 764 371 986 101 448 700 57 917 727 30 129 484 269 838 434 883 343 29 92 444 420 100 660 823 992 456 895 624 800 76 475 743 295 735 900 695 460 50 231 426 498 955 255 377 38 409 994 326 143 919 344 965 180 689 142 400 840 832 439 39 788 786 414 699 585 683 433 201 349 858 647 374 375 401 750 228 992 303 755 589 836 69 562 264 689 339 716 705
Output: 512

Constraints:

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

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