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 ll long long
const int N = 1e5 + 5;
bool maximize(int &a, int b) {
if(a >= b) return true;
a = b;
return false;
}
int n;
int dp[2][N];
void solve() {
cin >> n;
int cur = 0;
memset(dp[cur], -0x3f, sizeof(dp[cur]));
dp[cur][0] = 0;
int sum = 0;
for(int i = 1, x; i <= n; ++i) {
cin >> x; sum += x;
cur ^= 1;
memset(dp[cur], -0x3f, sizeof(dp[cur]));
for(int diff = 0; diff < N; ++diff) {
maximize(dp[cur][diff], dp[cur ^ 1][diff]);
if(diff + x < N) maximize(dp[cur][diff + x], dp[cur ^ 1][diff] + x);
if(diff >= x) maximize(dp[cur][diff - x], dp[cur ^ 1][diff]);
if(x >= diff) maximize(dp[cur][x - diff], dp[cur ^ 1][diff] + x - diff);
}
}
cout << sum - dp[cur][0] << '\n';
}
signed main() {
ios::sync_with_stdio(0);
cin.tie(0); cout.tie(0);
int test = 1;
// cin >> test;
while(test--) solve();
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... |