From 06da1a30b29a550d0266e562a233ebc2d50dd5fe Mon Sep 17 00:00:00 2001 From: Ren Baoshuo Date: Thu, 15 Oct 2020 21:36:41 +0800 Subject: [PATCH] =?UTF-8?q?P1094=20=E7=BA=AA=E5=BF=B5=E5=93=81=E5=88=86?= =?UTF-8?q?=E7=BB=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit R39868074 --- problem/P1094/P1094.cpp | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) create mode 100644 problem/P1094/P1094.cpp diff --git a/problem/P1094/P1094.cpp b/problem/P1094/P1094.cpp new file mode 100644 index 00000000..c82b03eb --- /dev/null +++ b/problem/P1094/P1094.cpp @@ -0,0 +1,26 @@ +#include + +using namespace std; + +int main() { + int w, n, ans = 0, p[30005]; + cin >> w >> n; + for (int i = 0; i < n; i++) { + cin >> p[i]; + } + sort(p, p + n); + int l = 0, r = n - 1; + while (l <= r) { + if (p[l] + p[r] <= w) { + l++; + r--; + ans++; + } + else { + r--; + ans++; + } + } + cout << ans << endl; + return 0; +}