CT33099

The Frugal Pairs of Tuskmore

MediumL4 · Loop LordAcceptance: 0.0%XP: 35

It is audit day at the boar woods of Tuskmore. Eklavya spreads the scrolls records across the table and picks up a sharp pencil. 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 <= 3507; 0 <= a[i],k <= 1000000.

Example 1:

Input: 1271 92224 412337 647284 279744 626824 245306 915660 771122 938717 782916 138356 518094 32381 13998 925041 662730 79556 551550 377766 7129 25133 400004 769709 910701 419065 301910 484304 396551 363800 32470 738080 768685 381523 191617 422333 32298 557191 762307 526311 271419 227688 352395 507861 347584 997749 341772 815535 627787 757614 943397 381997 702853 377682 666907 48116 713454 349186 641518 990557 455083 54766 961858 134271 787701 759781 770166 531744 850928 554700 360007 978505 937066 495156 768675 94491 805086 825354 756051 166517 200133 921110 519078 953087 658217 412077 345550 678781 340765 252718 991715 326706 333380 796106 306564 448620 676572 985943 128618 535216 707298 395380 790300 285018 525785 524682 308595 620449 423543 443846 803465 946270 916099 820991 58899 151585 865…
Output: 5171

Example 2:

Input: 2052 234234 894113 456966 119172 212219 988355 38987 10857 223449 807524 956087 13891 193356 845209 942076 315263 92754 527868 940312 730498 115124 605429 592569 715461 631981 400388 308769 24836 132967 410246 978808 464751 83507 354756 691348 907599 284552 669002 572837 394844 264651 9188 644213 602818 730283 60529 706640 832896 451293 831591 204479 49311 697961 749364 545998 739768 611221 102576 807669 692976 256981 603867 919077 675618 159490 234725 301565 153937 908241 319867 32121 652962 478618 330732 704117 561997 305569 244088 222154 408619 162871 924766 720929 281843 306778 235710 720596 768496 173477 607345 957068 150068 837985 645707 308278 63150 459801 179522 187168 567450 925993 783177 270812 668236 802274 455812 745166 166781 998622 530990 277768 568277 568156 472113 364051 51…
Output: 58354

Example 3:

Input: 3139 843852 608176 590128 961003 331212 304219 399989 526056 333754 956848 680378 642167 567307 59830 147709 597252 185998 481243 472743 941093 527122 588793 743769 931686 975953 362713 389736 527721 119657 588317 803586 818977 97882 151560 844547 309295 135367 748952 76332 747802 729145 648677 943132 429868 370823 408436 997128 540966 515436 662619 678157 603298 535216 497874 769528 186029 266715 989607 271298 783367 561576 940069 367279 249769 710812 748389 505525 715666 310874 869851 789391 570446 752452 44491 994634 685061 485305 899819 122682 83413 118725 799711 198104 725898 917559 798995 695664 719431 51206 474028 843300 880861 95348 969300 107680 959814 350803 303265 546359 9415 747524 254956 145054 534004 867247 537675 347382 208984 481256 681869 548375 828908 705573 273967 852822…
Output: 1742901

Constraints:

2 <= n <= 3507; 0 <= a[i],k <= 1000000.

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