CT48630

Piper's segments Reckoning

MediumL5 · Recursion RenegadeAcceptance: 0.0%XP: 60

Caravans arrive at the garden city of Petalbrook with crates of segments, and Piper the assayer must account for every last one. 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 <= 3713; 1 <= a[i],k <= 1000000.

Example 1:

Input: 3425 1821064 770769 635941 886492 623132 755318 651931 569581 343249 975666 676377 971261 48848 794154 252190 798936 878169 252971 322051 50177 56109 295585 276026 689934 669224 830110 598384 505654 40651 293389 75521 754402 513847 50360 128635 537021 423424 23265 19257 628721 256775 711474 179550 979459 905736 5391 685940 482768 213085 559948 231635 74850 680961 611368 771631 221270 846978 376423 992119 180149 801009 146216 580722 258231 379946 48826 815845 38250 988912 902113 590202 514669 463975 628361 363210 807012 568584 547704 576586 525524 634229 453835 93929 175926 282540 217913 362299 929436 873375 273113 363581 586908 63416 956964 703398 167198 957129 875680 224595 411177 699122 211655 727329 174833 899148 204140 329739 628300 893203 44005 950900 976729 512246 150740 378921 75159…
Output: 5770875

Example 2:

Input: 2598 767831 523416 833146 710306 595968 930334 404292 746293 144175 421900 125483 524774 366325 238115 358354 34255 873204 562306 106877 987820 240030 669664 667995 66282 651026 113101 736612 785314 527628 48887 447527 257010 422883 674611 284049 521077 379734 932278 593725 196450 115387 335253 150062 187609 51931 753724 962791 574734 511505 590962 387222 726305 417681 778186 728916 701722 208051 935382 717788 467357 454021 774247 923640 977840 353280 535408 636329 953958 901899 732103 777153 150863 736015 478185 628498 688388 799111 722746 709752 291451 187826 926963 502303 235551 302152 39027 536880 397834 276960 256338 422442 25786 876386 343356 294782 551719 608959 289646 289925 260581 563461 39517 17653 319081 511823 201982 307957 74327 333245 719699 689332 877367 479485 445983 449566…
Output: 1009386

Example 3:

Input: 1329 1362522 829220 364179 32241 521443 340901 780105 155892 238752 237112 346234 516523 975244 151999 768919 520508 130254 211656 1242 499794 530913 137906 860580 406240 51475 961084 804105 731455 62630 944584 891466 726185 749824 59554 103189 462621 883074 264807 384985 251267 497531 883712 868987 496591 142270 178060 252559 89312 375237 928506 393744 94635 866497 333029 890558 432600 358926 881404 447382 519359 686204 629777 864624 552266 530162 948509 570758 131065 766115 97240 959983 979502 257734 646731 871324 887300 949256 379565 171251 790073 103856 467467 816109 171493 538552 47016 332070 166580 110808 570189 848085 521479 897944 242674 886478 466063 987398 922683 77597 456532 995281 53215 817105 490215 477826 407189 673754 296056 231690 684364 617485 752237 131702 728543 930123 8…
Output: 713642

Constraints:

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

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