Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <bits/stdc++.h>
- using namespace std;
- ifstream fin("niceset.in");
- ofstream fout("niceset.out");
- #define int long long
- vector<int> v;
- int n, maxSum;
- void read() {
- fin >> n >> maxSum;
- v.resize(n);
- for (int &it : v) {
- fin >> it;
- }
- }
- void sortArr() {
- sort(v.begin(), v.end());
- int i = 0;
- int j = n - 1;
- vector<int> aux;
- while (i <= j) {
- if (i == j) {
- aux.push_back(v[i]);
- } else {
- aux.push_back(v[j]);
- aux.push_back(v[i]);
- }
- i = i + 1;
- j = j - 1;
- }
- v = vector<int>(aux.rbegin(), aux.rend());
- }
- signed main() {
- read();
- sortArr();
- for (int it : v) cerr << it << ' ';
- vector<int> ans;
- int currSum = 0, sumOfPs = 0;
- for (int it : v) {
- sumOfPs += llabs(currSum - it * ans.size());
- if (sumOfPs <= maxSum) {
- ans.push_back(it);
- } else {
- break;
- }
- currSum += it;
- }
- fout << ans.size() << endl;//*/
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement