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 <iostream>
using namespace std;
const int M = 1e5 + 5;
int dp[505][2*M+5], v[505];
int main() {
int n, S = 0;
cin >> n;
for(int i=1; i<=n; i++) cin >> v[i], S += v[i];
for(int j=0; j<=2*M; j++) dp[0][j] = -1e9;
dp[0][M] = 0;
for(int i=1; i<=n; i++) {
for(int j=0; j<=2*M; j++) {
dp[i][j] = dp[i-1][j];
if(j + v[i] <= 2 * M) dp[i][j] = max(dp[i][j], dp[i-1][j+v[i]] + v[i]);
if(j - v[i] >= 0) dp[i][j] = max(dp[i][j], dp[i-1][j-v[i]] + v[i]);
}
}
cout << S - dp[n][M] / 2 << '\n';
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... |