# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|
88916 | | heon | Kas (COCI17_kas) | C++11 | | 526 ms | 198380 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;
#define all(x) x.begin(), x.end()
typedef vector <int> vi;
typedef pair<int,int> ii;
typedef long long ll;
const int MOD = 1e9 + 7;
vi v;
int dp[100005][505];
int f(int n, int ind, int diff, int sum){
if(ind == n && diff != 0) return 0;
if(ind == n && diff == 0) return sum;
if(dp[diff][ind] != -1) return dp[diff][ind];
return dp[diff][ind] = max({f(n, ind + 1, diff + v[ind], sum + v[ind]), f(n, ind + 1, abs(diff - v[ind]), sum + v[ind]),
f(n, ind + 1, diff, sum)});
}
int main(){
ios_base::sync_with_stdio(false);
cin.tie(0);
int n;
cin >> n;
v.resize(n);
memset(dp, -1, sizeof(dp));
for(int i = 0; i < n; i++){
cin >> v[i];
}
int sum = accumulate(all(v), 0);
int ret = f(n, 0, 0, 0);
cout << ret / 2 + (sum - ret);
}
# | 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... |