From 9f949607c27973c29d4fea737a1e54d84695fccc Mon Sep 17 00:00:00 2001 From: TooYoungTooSimp <6648049+TooYoungTooSimp@users.noreply.github.com> Date: Sat, 13 Jul 2019 18:40:26 +0800 Subject: [PATCH] Sat, 13 Jul 2019 18:40:26 +0800 --- OnlineJudges/lydsy/2748.cpp | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) create mode 100644 OnlineJudges/lydsy/2748.cpp diff --git a/OnlineJudges/lydsy/2748.cpp b/OnlineJudges/lydsy/2748.cpp new file mode 100644 index 0000000..d06f24c --- /dev/null +++ b/OnlineJudges/lydsy/2748.cpp @@ -0,0 +1,23 @@ +#include +using namespace std; +bool f[55][1050]; +int main() +{ + int n, b, m, c; + scanf("%d%d%d", &n, &b, &m); + f[0][b] = true; + for (int i = 1; i <= n; i++) + { + scanf("%d", &c); + for (int j = 0; j <= m; j++) + { + if (j >= c) f[i][j] |= f[i - 1][j - c]; + if (j <= m - c) f[i][j] |= f[i - 1][j + c]; + } + } + int ans = -1; + for (int i = 0; i <= m; i++) + if (f[n][i]) ans = i; + printf("%d", ans); + return 0; +} \ No newline at end of file