CT31388

Archivist's segments Frugal Pairs

MediumL4 · Loop LordAcceptance: 0.0%XP: 35

Archivist inherited the counting house at the honey farms of Buzzwell along with its curious bookkeeping system for segments. Time to make sense of it. 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 <= 3310; -1000000 <= a[i],k <= 1000000000.

Example 1:

Input: 2385 1485386231 976205704 468332354 884467844 449791776 602267237 925418009 186080738 419390529 376306483 657160022 943561611 555481637 377450517 101603889 360962627 854918529 646024312 112350711 395570940 904177488 683470779 85901216 315986061 191158705 706618281 738298745 658962962 733538583 585430877 560303893 198957231 299059583 401125303 628787568 368889195 961121104 81032859 705340817 683896882 900107795 642657899 960031258 682162222 718618385 406891204 612599442 792653527 896169170 662579994 334813645 722659909 466252535 605620933 602837555 381329372 235250001 392784012 736431135 537990672 579345488 222426212 513320088 406657553 877713609 907569143 970452069 100131684 194795394 164297355 195703111 197169649 263672669 476735156 551018241 359766076 746491695 281380204 922170804 307683…
Output: 2488860

Example 2:

Input: 1637 1712810831 259535669 367150474 371498908 273213197 686094548 713022986 227253597 223399739 227465307 786780056 356124836 660137265 598097483 780165135 831137833 907145663 712340978 484857984 570285773 979201389 370272660 951765159 898651710 14889145 754110246 822008259 54752936 674098556 21946206 675730638 637974540 505961942 422359158 247469238 21060302 36199014 671031771 404992009 478191426 465096499 171495249 352270385 526465452 336062812 940451094 86707857 95648149 442532712 415350941 602633908 355596717 296039860 825669433 715480823 46512461 42301670 649846604 686412843 984295953 316419842 639600521 4086447 529653140 824397148 229587549 522323064 492435901 927634115 894329774 774862368 685708136 243401687 758383829 97213736 783616873 647158024 554967172 751172821 199127805 811117…
Output: 1277388

Example 3:

Input: 1694 1476227304 567321979 165508657 896858667 115586192 604167624 667705494 119556159 2536491 462916408 822116122 913637970 641020667 541754416 213753748 826860706 534781219 985261206 770310667 616592070 339322915 440072432 662918485 949468613 248056998 422754138 342403001 926520437 412023058 219074580 912635630 961250761 600597927 448972742 646903639 625150465 700574254 931509132 454408301 439277494 989410584 626831628 155856570 993064798 930488967 350376659 208399793 766664236 700628440 373298490 421425214 232041319 842771143 313326170 688038874 532714847 924157181 595756024 642862403 467766900 897264789 608209109 854370612 55273196 557674634 225138531 449003245 858329875 910378738 525427220 202665283 804423874 50627823 569882744 700912169 286012 811171992 796520642 685058835 372416341 1…
Output: 1229949

Constraints:

2 <= n <= 3310; -1000000 <= a[i],k <= 1000000000.

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