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;
const int MAXN = 1005;
const int K = MAXN * MAXN / 4;
int m, a[MAXN];
int dp[MAXN][MAXN * MAXN / 2];
long long L;
int main(){
ios_base::sync_with_stdio(false); cin.tie(0);
cin >> m >> L;
for(int i = 0; i < 2 * m + 1; ++i) cin >> a[i];
for(int i = 0; i < 2 * m + 1; ++i){
// dp[i][j] = max{dp[i - 1][j - x * (i - m)] + x}
for(int j = 0; j < MAXN * MAXN / 2; ++j){
dp[i][j] = -1e9;
for(int x = 0; x <= a[i]; ++x){
if(j - x * (i - m) >= 0 && j - x * (i - m) < MAXN * MAXN / 2){
if(i) dp[i][j] = max(dp[i][j], dp[i - 1][j - x * (i - m)] + x);
else if(j - x * (i - m) == K) dp[i][j] = max(dp[i][j], x);
}
}
}
}
if(L + K < 0 || L + K >= MAXN * MAXN / 2) cout << "impossible\n";
else if(dp[2 * m][L + K] < 0) cout << "impossible\n";
else cout << dp[2 * m][L + K];
return 0;
}
# | 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... |