CT33111

Hema's segments Frugal Pairs

MediumL4 · Loop LordAcceptance: 0.0%XP: 35

Hema found an old ledger of segments in the customs house attic at the saffron fields of Marigold Row. The margin notes pose a precise question. 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 <= 3945; 1 <= a[i],k <= 1000.

Example 1:

Input: 1528 841 499 355 201 636 706 117 243 396 652 323 770 701 5 187 71 963 514 876 29 50 390 340 512 270 85 115 200 676 75 990 852 170 832 212 733 675 694 476 118 927 639 959 782 220 85 170 96 452 312 19 723 311 832 965 207 970 394 101 481 616 507 51 305 944 944 88 193 998 189 984 448 397 538 48 622 478 153 34 706 67 40 501 400 700 889 795 655 4 152 844 66 432 462 977 415 319 564 489 126 973 858 563 920 148 48 276 818 528 439 91 90 44 199 181 891 544 586 338 681 537 152 705 222 149 716 255 408 826 710 993 663 17 330 805 819 460 82 595 472 723 697 840 751 824 43 250 133 238 820 500 885 62 743 901 849 835 859 374 844 859 333 247 212 292 218 333 54 435 781 24 434 456 333 893 569 192 312 178 927 321 589 57 853 943 317 868 642 258 892 432 516 160 786 854 431 190 944 614 904 511 526 202 824 630 658 7…
Output: 411380

Example 2:

Input: 2997 1119 126 758 147 710 11 364 590 286 45 279 823 91 226 636 860 128 253 92 848 249 436 222 858 345 690 63 252 827 893 655 485 380 123 226 254 276 966 735 506 746 482 790 535 695 159 399 115 58 445 387 516 548 34 522 754 111 457 794 211 407 289 762 598 540 17 905 845 472 553 497 159 210 474 432 240 648 717 3 472 797 908 596 686 846 715 326 699 722 353 230 160 326 532 327 827 725 20 519 891 207 213 514 170 20 474 178 682 197 243 336 771 791 849 60 55 151 744 692 744 574 452 403 866 282 560 918 220 851 559 752 654 579 349 440 327 756 664 176 502 537 161 15 359 776 312 827 379 866 190 40 752 998 527 102 958 150 533 40 201 987 845 72 306 836 14 55 189 914 546 730 647 786 800 995 329 296 115 808 175 146 816 490 18 873 117 809 854 869 303 874 932 780 966 838 713 59 131 532 238 821 827 770 142 …
Output: 2719548

Example 3:

Input: 2448 23 78 482 173 161 241 666 762 487 304 285 845 937 443 236 893 872 993 970 890 59 668 713 128 398 359 492 590 49 772 200 803 698 418 15 757 339 843 660 101 75 773 144 37 457 744 252 102 823 25 383 729 667 783 810 181 50 614 115 920 148 210 151 911 107 837 196 884 476 236 630 100 415 332 935 908 70 977 790 652 897 905 352 119 724 680 288 172 628 315 763 697 22 62 722 215 663 174 823 969 604 451 392 581 17 366 873 642 774 555 762 221 291 629 477 209 660 147 116 992 790 690 766 945 372 750 508 258 774 818 626 427 298 924 6 66 773 134 512 846 233 581 927 480 379 758 108 164 161 921 387 509 554 547 536 709 191 518 298 461 478 186 169 46 218 954 739 728 677 174 533 995 599 381 191 153 358 825 251 296 949 805 247 810 439 25 668 742 417 973 564 257 587 544 722 139 284 261 75 324 313 929 56 474…
Output: 945

Constraints:

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

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