CT35167

The Frugal Pairs Beneath Willowford

MediumL5 · Recursion RenegadeAcceptance: 0.0%XP: 60

Navigator runs the kiln at the river town of Willowford. Today the books show a list of panels, and the numbers must be worked out before sundown. 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 <= 3265; -1000000 <= a[i],k <= 1000.

Example 1:

Input: 2833 -331080 -693175 -338961 -577482 -387644 -291710 -508879 -513868 -206717 -320162 -80898 -140563 -783535 -794290 -613375 -136324 -818320 -251257 -643619 -235894 -535810 -951731 -422871 -655229 -685511 -158193 -311799 -755521 -278204 -324331 -253992 -783049 -794093 -410635 -786576 -250113 -889074 -83643 -290015 -767723 -760969 -540396 -232591 -651450 -837124 -134090 -578875 -375953 -306653 -270176 -850899 -695038 -516092 -539938 -352111 -686106 -570936 -396418 -671685 -175152 -391780 -437369 -305801 -471987 -805517 -335679 -545047 -718112 -891740 -636278 -62753 -312317 -879924 -363961 -773852 -9271 -886533 -853484 -396730 -765484 -993631 -18365 -763763 -61503 -816213 -247764 -443609 -620901 -843410 -697973 -164922 -905757 -217325 -751199 -77776 -379878 -382890 -169663 -105176 -980554 -52…
Output: 3789930

Example 2:

Input: 1504 -261989 -904298 -393819 -968176 -195719 -197239 -602815 -962034 -675603 -58873 -81232 -136942 -629373 -183484 -946717 -448414 -933618 -916528 -666769 -24073 -835493 -366233 -980459 -907222 -455566 -407699 -489981 -130816 -506691 -604567 -367787 -80384 -386187 -976444 -344238 -316095 -868343 -739435 -421730 -391687 -755654 -307329 -340124 -332177 -486999 -391750 -74615 -182175 -70385 -451196 -178020 -976653 -439940 -975122 -268930 -856879 -443300 -751948 -488866 -674806 -301017 -786741 -357471 -801535 -615575 -843210 -13709 -225347 -510155 -177638 -538036 -906569 -930770 -792240 -174875 -465800 -373264 -767188 -430294 -114225 -362986 -973829 -282010 -958904 -936052 -252233 -163809 -391748 -223859 -149421 -662980 -384110 -131384 -222839 -583587 -59038 -760677 -929064 -112011 -246808 -22…
Output: 1089703

Example 3:

Input: 1508 -940793 -5928 -680563 -842457 -407152 -431257 -756903 -518881 -862414 -73977 -511554 -278279 -58235 -548405 -133802 -304810 -119088 -737883 -714064 -696843 -273553 -311730 -149554 -97266 -242018 -17195 -522330 -399556 -693355 -173964 -497324 -365044 -318590 -785081 -926722 -256310 -611678 -424781 -329971 -678154 -964415 -903571 -570991 -31948 -492269 -44689 -467624 -998406 -790047 -98094 -487710 -728270 -79912 -167041 -870221 -321475 -91825 -770090 -825732 -431335 -494795 -876616 -150194 -213756 -279708 -556199 -29180 -385514 -261203 -36931 -288782 -957615 -800338 -612721 -834412 -324717 -631086 -107196 -35387 -222995 -139252 -73103 -407319 -265348 -606351 -190450 -593103 -890417 -280007 -217403 -872837 -56791 -658914 -641844 -840861 -445068 -939940 -391119 -532436 -130978 -374708 -15…
Output: 627115

Constraints:

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

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