# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|
740911 | | dsyz | Kas (COCI17_kas) | C++17 | | 406 ms | 391724 KiB |
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;
using ll = int;
#define MAXN (200005)
ll dp[505][MAXN];
int main() {
ios_base::sync_with_stdio(false);cin.tie(0);
ll N;
cin>>N;
ll arr[N];
ll total = 0;
for(ll i = 0;i < N;i++){
cin>>arr[i];
total += arr[i];
}
for(ll i = 0;i < N;i++){
for(ll j = 0;j < MAXN;j++){
dp[i][j] = -1e9;
}
}
dp[0][100001] = 0;
dp[0][100001 + arr[0]] = arr[0];
dp[0][100001 - arr[0]] = 0;
for(ll i = 1;i < N;i++){
for(ll j = 0;j < MAXN;j++){
dp[i][j] = dp[i - 1][j];
if(j + arr[i] < MAXN) dp[i][j] = max(dp[i][j],dp[i - 1][j + arr[i]]);
if(j - arr[i] >= 0) dp[i][j] = max(dp[i][j],dp[i - 1][j - arr[i]] + arr[i]);
}
}
cout<<dp[N - 1][100001] + (total - 2 * dp[N - 1][100001])<<'\n';
}
# | 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... |