Samkit5025

Untitled

Jun 27th, 2022
49
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.59 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3.  
  4. int selfSufficentColony(int N, int X, vector<int> &A)
  5. {
  6.     sort(A.begin(), A.end(), greater<int>());
  7.  
  8.     for (int i = 1; i < N; i++)
  9.     {
  10.         A[i] += A[i - 1];
  11.     }
  12.  
  13.     int ans = 0;
  14.     for (int i = 0; i < N; i++)
  15.     {
  16.         if (A[i] >= ((i + 1) * X))
  17.         {
  18.             ans = i + 1;
  19.         }
  20.     }
  21.  
  22.     return ans;
  23. }
  24.  
  25. int main()
  26. {
  27.     int N, X;
  28.     cin >> N >> X;
  29.  
  30.     vector<int> Q(N);
  31.     for (int i = 0; i < N; i++)
  32.     {
  33.         cin >> Q[i];
  34.     }
  35.  
  36.     cout << selfSufficentColony(N, X, Q) << endl;
  37. }
  38.  
Advertisement
Add Comment
Please, Sign In to add comment