Advertisement
STANAANDREY

niceset

Jun 14th, 2022
1,015
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.07 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3. ifstream fin("niceset.in");
  4. ofstream fout("niceset.out");
  5. #define int long long
  6. vector<int> v;
  7. int n, maxSum;
  8.  
  9. void read() {
  10.     fin >> n >> maxSum;
  11.     v.resize(n);
  12.     for (int &it : v) {
  13.         fin >> it;
  14.     }
  15. }
  16.  
  17. void sortArr() {
  18.     sort(v.begin(), v.end());
  19.     int i = 0;
  20.     int j = n - 1;
  21.  
  22.     vector<int> aux;
  23.     while (i <= j) {
  24.         if (i == j) {
  25.             aux.push_back(v[i]);
  26.         } else {
  27.             aux.push_back(v[j]);
  28.             aux.push_back(v[i]);
  29.         }
  30.         i = i + 1;
  31.         j = j - 1;
  32.     }
  33.     v = vector<int>(aux.rbegin(), aux.rend());
  34. }
  35.  
  36. signed main() {
  37.     read();
  38.     sortArr();
  39.  
  40.     for (int it : v) cerr << it << ' ';
  41.  
  42.  
  43.     vector<int> ans;
  44.     int currSum = 0, sumOfPs = 0;
  45.     for (int it : v) {
  46.         sumOfPs += llabs(currSum - it * ans.size());
  47.  
  48.         if (sumOfPs <= maxSum) {
  49.             ans.push_back(it);
  50.         } else {
  51.             break;
  52.         }
  53.  
  54.         currSum += it;
  55.     }
  56.  
  57.     fout << ans.size() << endl;//*/
  58.     return 0;
  59. }
  60.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement