Submission #949639

#TimeUsernameProblemLanguageResultExecution timeMemory
949639ifateenUplifting Excursion (BOI22_vault)C++17
20 / 100
2519 ms16472 KiB
#include <bits/stdc++.h> using namespace std; #define int long long const int OFFSET_SUM = 5e5 + 5e3 + 5, MAXN = 1e6 + 1e4 + 69; int dp[2][MAXN + 1]; void add(int x, int count) { int diff = x * count; for (int i = 0; i <= MAXN; ++i) { dp[1][i] = dp[0][i]; if (0 <= i - diff && i - diff <= MAXN) dp[1][i] = max(dp[1][i], dp[0][i - diff] + count); } for (int i = 0; i <= MAXN; ++i) dp[0][i] = dp[1][i]; } signed main() { for (auto& i : dp[0]) i = -1e9; for (auto& i : dp[1]) i = -1e9; dp[0][OFFSET_SUM] = 0; int n, l; cin >> n >> l; for (int i = -n; i <= n; ++i) { int x; cin >> x; int cnt = 1; while (cnt <= x) { add(i, cnt); x -= cnt; cnt *= 2; } if (x > 0) add(i, x); } if (-OFFSET_SUM > l || l > OFFSET_SUM) { cout << "impossible"; return 0; } int ans = dp[0][OFFSET_SUM + l]; if (ans < 0) cout << "impossible"; else cout << ans; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...