1334B - Middle Class - CodeForces Solution


greedy sortings *1100

Please click on ads to support us..

Python Code:

for t in range(int(input())):
    n,x=map(int,input().split())
    arr=sorted(list(map(int,input().split())))[::-1]
    h=0
    a=0
    while(h>=0 and a<n):
        if(arr[a]-x+h>=0):
            h+=arr[a]-x
            a+=1
        else:
            break
    print(a)

C++ Code:

#define ALLAH_IS_THE_GREATEST
ALLAH_IS_THE_GREATEST
#include<bits/stdc++.h>
#define ll long long
#define fl float
#define pb push_back
#include <cmath>
#define no cout << "NO\n" ;
#define yes cout << "YES\n" ;
#define elif else if
#define en <<endl;
#define ld long double
#define r0 return 0;
using namespace std;
string s,s1,h,g,o,u, h1, all = "abcdefghijklmnopqrstuvwxyz";
vector<string> sv, sw, sv1, sw1;
vector<ll> v,vv,v1, w,ww,vw ;
map<ll, ll > mp, mp1 ;
set < ll > st, st1;
float fl2, fl1;
char ch='a', ch1;
int main ()
{
    ios_base::sync_with_stdio(0);
    ll mx = -1e18,  mn = 1e18, mx1 = -10e9, mn1 = 10e9;
    ll sum=0, ans=0, q, x, y, f, e= 0,  b,t, c=0,d=0,m=0,r,k,p ;
    ll  mid=0,a, cnt = 0, n=0;
    ll l;
    cin >> t;
    for ( int i = 0 ; i < t; i ++)
    {
        cin >> a >> b ;
        for ( int j = 0 ; j < a; j ++)
        {
            cin >> n ;
            v.pb(n);
        }
        sort ( v.rbegin() , v.rend()) ;
        for (int i = 0 ; i < v.size() ; i ++ )
        {
            if (v[i] >= b)
            {
                c++ ;
                d += v[i] - b;
            }
            else
            {
               if ( d + v[i] >= b)
               {
                   c ++ ;
                   d-= b- v[i] ;
               }
            }
        }
        cout << c en
        v.clear() , d = 0 , c =0 ;
    }
}
/**

**/


Comments

Submit
0 Comments
More Questions

1712D - Empty Graph
1712B - Woeful Permutation
1712C - Sort Zero
1028B - Unnatural Conditions
735B - Urbanization
746C - Tram
1278B - A and B
1353D - Constructing the Array
1269C - Long Beautiful Integer
1076A - Minimizing the String
913C - Party Lemonade
1313A - Fast Food Restaurant
681A - A Good Contest
1585F - Non-equal Neighbours
747A - Display Size
285A - Slightly Decreasing Permutations
515C - Drazil and Factorial
1151E - Number of Components
1151F - Sonya and Informatics
556A - Case of the Zeros and Ones
867A - Between the Offices
1569A - Balanced Substring
260A - Adding Digits
1698C - 3SUM Closure
1029B - Creating the Contest
1421A - XORwice
1029A - Many Equal Substrings
1675D - Vertical Paths
1271C - Shawarma Tent
805A - Fake NP