Submission #994133

#TimeUsernameProblemLanguageResultExecution timeMemory
994133vjudge1Kas (COCI17_kas)C++17
70 / 100
67 ms1224 KiB
#include<bits/stdc++.h> using namespace std; const int SM = 1e5+1, inf = 1e9; int dp[2][SM]; int main() { int n; cin >> n; int a[1 + n]; int x = 0; for(int i = 1; i <= n; ++i) { cin >> a[i]; x += a[i]; } for(int j = 1; j <= x; j++) dp[0][j] = -inf; for(int i = 1; i <= n; i ++) { bool b = i & 1, nb = !b; for(int j = 0; j <= x; j++) { dp[b][j] = dp[nb][j]; if(j >= a[i]) dp[b][j] = max(dp[b][j], dp[nb][j - a[i]]); if(a[i] + j <= x) dp[b][j] = max(dp[b][j], dp[nb][j + a[i]] + a[i]); // cerr << "dp[" << i << "][" << j << "] = " << dp[b][j] << endl; } } int mx = dp[n & 1][0]; cout << mx + (x - 2 * mx) << endl; return 0; }
#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...