From ad33854e6315aa6de6bb0e05241c888b5fa2574b Mon Sep 17 00:00:00 2001 From: Baoshuo Date: Sat, 14 May 2022 20:16:50 +0800 Subject: [PATCH] B - At Most 3 (Judge ver.) https://atcoder.jp/contests/abc251/submissions/31667423 --- AtCoder/ABC251/B/B.cpp | 52 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 52 insertions(+) create mode 100644 AtCoder/ABC251/B/B.cpp diff --git a/AtCoder/ABC251/B/B.cpp b/AtCoder/ABC251/B/B.cpp new file mode 100644 index 00000000..077bcc1d --- /dev/null +++ b/AtCoder/ABC251/B/B.cpp @@ -0,0 +1,52 @@ +#include + +using std::cin; +using std::cout; +const char endl = '\n'; + +const int N = 305; + +int n, w, a[N], ans; +bool vis[1000005]; + +int main() { + std::ios::sync_with_stdio(false); + + cin >> n >> w; + + for (int i = 1; i <= n; i++) { + cin >> a[i]; + } + + for (int i = 1; i <= n - 2; i++) { + for (int j = i + 1; j <= n - 1; j++) { + for (int k = j + 1; k <= n; k++) { + if (a[i] + a[j] + a[k] <= w) { + vis[a[i] + a[j] + a[k]] = true; + } + } + } + } + + for (int i = 1; i <= n - 1; i++) { + for (int j = i + 1; j <= n; j++) { + if (a[i] + a[j] <= w) { + vis[a[i] + a[j]] = true; + } + } + } + + for (int i = 1; i <= n; i++) { + if (a[i] <= w) { + vis[a[i]] = true; + } + } + + for (int i = 1; i <= 1000000; i++) { + if (vis[i]) ans++; + } + + cout << ans << endl; + + return 0; +}