CT43000

The Frugal Pairs at Reedmarsh

MediumL5 · Recursion RenegadeAcceptance: 0.0%XP: 60

In the willow walks of Reedmarsh, Wren the log keeper keeps careful count of the ribbons. outscore the rival chapter, every figure matters. 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 <= 3777; -1000000 <= a[i],k <= 1000000.

Example 1:

Input: 129 -695826 -399054 -612550 -975598 279256 -740677 378431 -559524 660507 796628 -779545 -604410 940480 392768 431545 -940477 482021 159842 -742470 410236 104035 -225395 136666 -128795 -879843 -888539 700993 725814 -576597 491901 646644 276446 -68932 -476569 -529720 405593 -589805 486357 445967 196823 -95735 814833 286527 178843 -793959 -174488 403443 423403 617657 588972 -137888 724575 678561 -969499 -598743 -622469 433743 -334263 306992 383808 56673 412353 202918 38044 197843 357157 -801972 369175 357026 454855 -381129 -789380 367444 -501533 171278 -803204 627254 888059 140250 528535 -710241 -488325 171823 -425379 467945 -520311 708782 -166108 801490 -868119 407842 703839 -304565 774302 -917514 801486 691286 278188 665203 32827 984869 194231 147926 393283 735852 -307805 617864 -227534 -67…
Output: 1319

Example 2:

Input: 2804 -541144 -758290 375282 -95939 430815 -311160 -876337 677994 848553 -111644 495848 -505476 530592 -499067 -111918 -153940 515845 -42606 -879864 309514 -785967 277819 -249951 935506 140631 611109 819372 608664 -347451 -201154 -173822 330515 -311302 -72929 -509529 624120 -53660 -637347 -791983 462285 -681612 848723 210377 -914891 528481 -582335 -267075 176870 317681 -917777 453579 160695 880346 -582431 892515 152429 280565 553988 -75189 235417 828429 503551 150681 -898658 744919 298231 -753046 101849 -487295 -676504 176751 8079 705282 75730 -512611 -512139 -206897 247752 -813834 -413525 -863789 -105052 692711 758253 216221 230986 353118 -482854 975499 852526 25794 802431 337567 558346 662744 229133 569029 659572 -347663 -89496 27696 597002 48803 -767974 -960614 825429 -238529 536703 6170…
Output: 995475

Example 3:

Input: 317 1101529 243068 -260523 -61611 101394 -144928 -939698 891486 -89543 861429 451839 183310 11815 -936090 299400 158326 510200 19263 36041 140139 -885194 -500525 513367 -345542 550119 -778818 -757583 -784471 631136 124220 -904137 -533319 93179 161176 6735 -73003 -627270 -177650 656002 -984899 -872834 14469 -698903 708671 -47873 -946248 460719 -219089 171114 34877 958385 -722337 -937941 660304 -260754 -473355 93389 370742 -177789 -547302 -408954 998360 -339506 262657 -714547 44433 -933476 555119 -817766 -892071 -94186 836141 -309968 -701825 140888 -94692 492978 536735 -946998 -264918 32736 -909847 396406 -302985 349569 685593 168665 274737 -557787 -300458 586038 -129945 -436533 231404 441872 -952477 66957 746983 877406 -714081 -809388 -601294 140208 695140 -21373 -982658 722103 -350306 4717…
Output: 46936

Constraints:

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

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