From c436e4bf97308fbb906e56afde81844e69a36416 Mon Sep 17 00:00:00 2001 From: Baoshuo Date: Sun, 24 Jul 2022 17:57:24 +0800 Subject: [PATCH] =?UTF-8?q?P8444=20=E4=B8=8D=E7=AD=89=E4=BB=B7=E4=BA=A4?= =?UTF-8?q?=E6=8D=A2=E6=B3=95=E5=88=99?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit https://www.luogu.com.cn/record/80991984 --- Luogu/P8444/P8444.cpp | 50 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 50 insertions(+) create mode 100644 Luogu/P8444/P8444.cpp diff --git a/Luogu/P8444/P8444.cpp b/Luogu/P8444/P8444.cpp new file mode 100644 index 00000000..3d00304b --- /dev/null +++ b/Luogu/P8444/P8444.cpp @@ -0,0 +1,50 @@ +#include +#include +#include + +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 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; +}