CT44648

Orin's Ledger of ribbons

MediumL5 · Recursion RenegadeAcceptance: 0.0%XP: 60

Legend says the vault under the ivory gates of Alabast opens only for a perfect tally of ribbons. Orin means to find out. 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 <= 2443; 0 <= a[i],k <= 1000000000.

Example 1:

Input: 929 1510617948 757704248 400696800 633424681 893521919 154899667 254263429 836343918 192179163 100129341 886332246 486433964 211198886 726313079 241588821 40783266 501841190 706735819 773663089 186434126 113026287 851391988 163467470 456201427 872792789 143292446 667423187 480203011 892292786 515195538 614525040 102040676 339732345 557169024 416550683 113305913 901421119 958357414 988877750 333730315 881080784 507520075 401323811 393383551 624557971 754499133 296882000 74747221 173094910 500020411 407611501 530041004 553694796 393097890 675477583 527421231 976986313 506982614 900189093 924238503 69960391 665144353 11324399 890274661 41202256 66772595 589637110 878600109 47209280 407387477 485520424 783243368 481487836 138827146 518353811 653196334 574528817 414419699 65913656 617675696 500…
Output: 378633

Example 2:

Input: 1013 42011777 977393253 943295791 899651433 878971535 819659443 134960374 859929078 432720096 772225909 634549377 15910953 605205215 122176288 555278935 747455987 572000523 504348394 529336593 435896618 829286213 441679116 288737050 628616374 925703771 398436549 756045130 122564385 417239211 628504910 243743450 630499410 559877171 112644443 287667777 101398751 899338280 546551233 805064202 218046621 579904670 776859577 484389597 936821077 345525154 642360470 158588184 165907334 884037639 334204080 956605703 267357067 634560122 996145263 179548057 9585752 321719370 633034541 463162659 848801955 846802957 170715686 140579050 158161443 822623138 661233326 762491527 995692087 53462491 580494027 650611415 731536522 55688112 589381196 734913762 277281040 209049813 552820149 873620618 225262547 1…
Output: 352

Example 3:

Input: 1660 919994822 690236135 785113194 977372184 485253565 333849482 338077602 520107859 666865069 58574835 855122765 472460889 409314569 475457687 62762606 195767090 85099540 707023451 794629019 775014703 321202209 435674166 319476243 38313693 798341347 179086092 539601203 921900062 747808839 968545468 240739708 56279807 809235212 178918870 776074856 976401054 220475628 890396316 207423908 743020922 532953122 394283656 577469640 927008085 875515859 453223590 51943186 80600166 717398510 217814435 627273565 645644620 265366523 867383333 174298375 730994445 324975947 687729744 249973313 144356818 912577271 787489572 194527330 969129776 974275412 286342932 475444907 843160785 85602453 274239081 911825073 582597878 805094869 542375880 923477907 912842886 721615747 288047721 287231347 546121451 478…
Output: 573871

Constraints:

2 <= n <= 2443; 0 <= a[i],k <= 1000000000.

Loading...
Test Cases:No test cases
No test cases available.