Submission #994030

#TimeUsernameProblemLanguageResultExecution timeMemory
994030vjudge1Kas (COCI17_kas)C++17
70 / 100
119 ms2528 KiB
#include<bits/stdc++.h> using namespace std; const int SM = 1001; bool dp[2][SM][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]; } dp[0][0][0] = true; for(int i = 1; i <= n; i ++) { bool b = i & 1, nb = !b; for(int j = 0; j <= x; j++) for(int k = 0; k <= x; k++) { dp[b][j][k] = dp[nb][j][k]; if(j >= a[i]) dp[b][j][k] |= dp[nb][j - a[i]][k]; if(k >= a[i]) dp[b][j][k] |= dp[nb][j][k - a[i]]; } } int mx = 0; for(int i = 0; i <= x; i++) if(dp[n & 1][i][i]) mx = i; 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...