CT56733

The Balmcrest Frugal Pairs

MediumL5 · Recursion RenegadeAcceptance: 0.0%XP: 60

It is audit day at the cedar groves of Balmcrest. Minstrel spreads the ribbons records across the table and picks up a sharp pencil. 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 <= 2743; -1000000 <= a[i],k <= 1000.

Example 1:

Input: 2651 -368121 -407716 -992529 -741458 -572515 -905158 -872598 -649808 -543850 -455012 -871163 -482753 -137073 -66502 -435454 -86802 -304448 -60024 -373873 -167543 -981134 -621565 -850243 -684831 -969025 -722787 -944886 -525395 -902242 -375570 -767278 -846696 -467157 -607143 -387923 -165401 -547610 -299035 -531905 -503851 -333418 -498086 -967045 -365186 -848574 -874317 -271952 -672458 -579867 -27758 -807470 -498053 -257462 -361824 -33165 -442505 -715600 -615272 -617174 -698600 -866901 -722110 -919811 -49679 -423138 -269458 -228149 -176923 -578432 -936270 -41398 -411304 -110520 -696946 -103820 -568196 -926504 -126252 -886071 -829036 -421533 -261608 -446680 -939009 -671914 -20634 -94196 -378165 -849932 -4019 -594852 -574738 -590902 -551350 -72677 -7776 -458560 -273747 -662651 -708261 -160871 -…
Output: 3270450

Example 2:

Input: 1695 -805459 -982048 -281075 -679831 -282911 -76347 -999088 -194179 -892052 -553382 -869673 -949339 -102693 -234267 -847167 -859301 -392876 -730180 -501948 -631251 -34011 -243423 -873267 -558806 -320727 -627095 -292422 -556908 -784464 -964743 -226690 -689367 -660944 -728790 -728207 -470058 -96534 -445374 -138207 -102759 -246562 -24610 -740737 -637418 -354129 -170427 -90290 -724433 -84510 -314272 -65379 -867134 -611421 -205220 -273624 -772623 -162044 -55726 -724488 -732607 -848483 -922615 -414876 -91002 -813573 -130471 -427423 -939189 -512816 -749978 -710051 -303534 -100717 -668121 -235755 -376091 -341733 -814711 -816223 -311944 -222536 -925688 -238280 -283814 -891372 -314380 -397910 -177820 -334222 -480792 -856038 -990730 -322305 -574852 -823452 -858917 -472667 -274092 -534170 -543852 -458…
Output: 967506

Example 3:

Input: 1228 -272002 -646115 -713908 -713143 -728202 -93571 -908163 -992888 -902390 -330114 -835613 -291581 -683815 -55085 -604316 -840919 -484219 -913463 -451414 -695924 -904326 -195879 -997560 -71807 -700056 -325389 -927741 -381022 -221694 -787046 -114380 -710225 -862110 -736862 -650660 -92805 -361281 -300920 -19426 -700934 -733168 -992119 -969300 -277084 -328328 -833772 -199359 -818464 -480347 -250160 -543259 -780442 -949320 -494819 -647865 -681168 -769975 -926522 -280096 -242549 -769125 -768297 -531065 -862936 -381723 -306329 -787158 -61637 -806102 -770813 -292096 -409166 -540582 -195581 -639763 -839019 -837918 -795158 -246215 -482187 -30175 -257753 -858271 -230491 -916963 -163279 -515107 -88524 -542288 -443786 -857784 -240630 -995020 -270267 -915325 -745214 -337805 -873298 -644478 -258498 -52…
Output: 727879

Constraints:

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

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