Submission #93105

#TimeUsernameProblemLanguageResultExecution timeMemory
93105Ahmad_ElsisyKas (COCI17_kas)C++14
70 / 100
549 ms198176 KiB
#include <bits/stdc++.h> #define pb push_back #define all(v) (v).begin() , (v).end() #define popcnt(x) __builtin_popcount(x) #define inf 0x3f3f3f3f #define watch(x) cout << (#x) << " is " << (x) << endl using namespace std; typedef long long ll; const int N = 505 , M = 1e5 + 4; int n , memo[N][M]; vector<int> a; int solve(int indx , int s){ if(indx == n){ return (!s ? 0 : -inf); } int &ret = memo[indx][s]; if(~ret) return ret; ret = -inf; ret = max(ret , a[indx] + solve(indx + 1 , s + a[indx])); ret = max(ret , solve(indx + 1 , abs(s - a[indx]))); ret = max(ret , solve(indx + 1 , s)); return ret; } int main() { ios::sync_with_stdio() , cin.tie(0) , cin.tie(0); int tot = 0; cin >> n; a.resize(n); for(int &x : a) cin >> x , tot += x; memset(memo , -1 , sizeof memo); int v = solve(0 , 0); cout << v + (tot - 2 * v) << '\n'; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...