This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#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 time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |