0
1
mirror of https://git.sb/baoshuo/OI-codes.git synced 2024-11-23 20:28:48 +00:00

P8444 不等价交换法则

https://www.luogu.com.cn/record/80991984
This commit is contained in:
Baoshuo Ren 2022-07-24 17:57:24 +08:00
parent 5ba81b4eba
commit c436e4bf97
Signed by: baoshuo
GPG Key ID: 00CB9680AB29F51A

50
Luogu/P8444/P8444.cpp Normal file
View File

@ -0,0 +1,50 @@
#include <iostream>
#include <algorithm>
#include <vector>
using std::cin;
using std::cout;
const char endl = '\n';
const int N = 1e6 + 5;
int n;
long long w;
int main() {
std::ios::sync_with_stdio(false);
cin.tie(nullptr);
cin >> n;
std::vector<int> a(n);
for (int &x : a) {
cin >> x;
}
std::sort(a.begin(), a.end());
cin >> w;
auto it = std::upper_bound(a.begin(), a.end(), w);
if (it == a.begin()) {
cout << 0 << endl;
exit(0);
} else {
it--;
}
int ans = 0;
long long sum = 0;
for (auto i = a.begin(); i != a.end(); i++) {
if ((sum += *i) <= *it) ans++;
else break;
}
cout << ans << endl;
return 0;
}