CT34754

Gita Counts the ribbons

MediumL4 · Loop LordAcceptance: 0.0%XP: 35

Caravans arrive at the cedar groves of Balmcrest with crates of ribbons, and Gita the quartermaster 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 <= 2590; -1000000 <= a[i],k <= 1000.

Example 1:

Input: 1167 -802650 -260748 409 -295516 -563447 -108891 -61952 -654010 -170263 -173251 -580091 -713081 -97595 -211220 -627140 -12525 -253008 -235989 -220188 -73435 -868535 -416631 -79209 -776859 -224477 -822162 -484175 -799437 -809444 -837863 -302572 -440536 -82131 -699882 -88382 -520128 -407851 -423366 -37402 -315715 -619565 -390071 -178885 -664775 -269852 -884463 -693816 -142121 -787289 -749132 -60003 -196761 -965222 -688425 -100911 -876906 -163684 -386656 -887442 -988144 -645405 -255550 -225098 -338716 -116220 -951480 -68041 -693727 -185497 -344380 -691969 -504229 -446626 -155749 -517952 -179487 -742756 -231938 -394909 -924782 -31766 -390201 -720923 -931997 -156825 -221283 -344508 -558733 -489511 -234545 -189763 -361281 -884110 -929279 -512807 -565414 -360123 -362251 -866285 -682443 -841441 -8…
Output: 444007

Example 2:

Input: 2587 -395074 -136046 -499757 -219704 -59157 -269897 -728406 -816215 -878122 -892616 -252146 -817471 -323293 -212147 -54443 -306606 -572713 -194984 -913008 -548851 -641981 -878588 -107324 -41778 -969784 -603737 -56472 -754087 -468320 -522028 -450581 -516917 -425418 -245307 -497189 -516391 -596241 -470930 -857473 -155918 -218405 -64917 -435226 -540094 -618204 -658784 -549571 -877352 -118401 -837570 -810325 -185279 -836633 -414450 -784074 -262927 -49194 -811102 -121973 -904549 -523236 -61654 -628193 -273864 -726435 -779468 -373526 -168273 -954787 -837923 -359447 -301547 -115090 -790887 -31689 -811101 -947336 -355130 -361360 -479719 -374359 -251304 -35581 -28678 -179951 -244014 -868799 -390852 -494665 -956643 -230451 -816572 -962955 -969098 -630653 -380628 -454596 -108756 -81935 -366122 -10067…
Output: 3092217

Example 3:

Input: 144 -217782 -16651 -702294 -925949 -224942 -737930 -875184 -439147 -606904 -152565 -121526 -200248 -159758 -321423 -787045 -530222 -942204 -626650 -205918 -161902 -436363 -213500 -707856 -354112 -498227 -926088 -293185 -30136 -935108 -928482 -778781 -614109 -706574 -183788 -69152 -729514 -952860 -33519 -615802 -98399 -899820 -57394 -890726 -331638 -676043 -810614 -440129 -70684 -887430 -11910 -407267 -800459 -38492 -443515 -820080 -869718 -91619 -148970 -454928 -100993 -714420 -774009 -59918 -641807 -740543 -515944 -672612 -921598 -852128 -992275 -354803 -117505 -41877 -216152 -304131 -510641 -781033 -76649 -864353 -861871 -163133 65 -776255 -982238 -274687 -698915 -362783 -893130 -306200 -206011 -178066 -662597 -70087 -591729 -136534 -220245 -688739 -941478 -363108 -460564 -666325 -615529…
Output: 9816

Constraints:

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

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