CT30185

The Frugal Pairs of the Azure ribbons

MediumL4 · Loop LordAcceptance: 0.0%XP: 35

Mason found an old ledger of ribbons in the chandlery attic at the dune sea of Caravanrest. 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 <= 1438; 1 <= a[i],k <= 1000000.

Example 1:

Input: 345 818203 772435 751332 621740 801795 140834 558722 55372 173547 640641 404059 754716 945867 811794 443451 302399 274863 500892 472794 117714 943818 351022 335839 446480 721771 466138 95845 352564 631053 51493 850234 963140 112375 511416 262517 381746 984491 936682 967536 260370 284930 91718 38897 627833 717158 964358 244594 999594 405925 731734 460515 755083 999000 235997 984634 501511 350199 302866 951253 783659 472654 954316 287350 198 649056 625147 49340 790552 752529 75891 640621 802779 752975 829295 329734 916155 260272 617778 98317 366334 415703 406082 667486 886746 961289 808430 864726 823590 82600 787914 798957 907188 369610 862101 624757 84018 625555 755279 494031 265447 215992 974635 172643 591510 225049 985265 865908 300797 779366 629811 747219 900850 555459 589683 568327 5935…
Output: 18416

Example 2:

Input: 1262 1763906 687603 450604 893305 33521 320289 802742 747649 488453 192312 306770 960295 903955 754857 61068 992297 53761 69579 389876 898420 948823 903753 294973 291833 390391 7222 927229 637261 471157 752480 840645 742855 145844 152095 71665 660523 722928 261225 499894 876143 438769 374384 798641 824545 835407 199532 24220 939134 824470 576662 734758 441464 526539 63593 358296 801748 777027 72843 657979 710217 810011 493129 815886 371428 161981 216538 781649 577656 442035 425151 317337 425514 862827 363043 687370 513268 997634 440841 450233 163680 491275 300925 348204 515431 245912 956198 488361 845855 773666 883285 719519 470980 259549 883484 388834 193514 534541 968425 256843 389543 817084 925978 47374 505441 326821 191913 412469 632945 480886 294575 336301 624578 257642 340259 105443 …
Output: 775462

Example 3:

Input: 112 1838442 568727 701798 147451 690000 107181 601660 561610 979876 624783 416687 125265 359106 320627 913757 599592 493906 105165 84574 456915 729081 413751 119022 885668 227071 727097 156034 837282 520460 633264 453054 2113 908089 118294 509773 476224 273505 92537 453837 553918 458164 795908 483526 825192 323478 765526 115214 481362 218243 507658 861326 225847 927497 909322 764265 489222 206926 206358 199178 830588 896388 577597 768934 765086 745527 608363 577628 273565 41504 712333 129992 789786 425920 714147 725639 101978 313852 636935 534959 930608 449061 953452 239914 576319 369232 275971 546247 464569 659960 474228 861999 276774 151771 89555 765670 321021 847384 749686 789992 376679 615125 146992 288248 446998 140955 927189 389482 533211 860773 682613 138450 276273 697950
Output: 6188

Constraints:

2 <= n <= 1438; 1 <= a[i],k <= 1000000.

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