Submission #1042878

#TimeUsernameProblemLanguageResultExecution timeMemory
1042878VMaksimoski008Kas (COCI17_kas)C++17
70 / 100
2070 ms49648 KiB
#include <bits/stdc++.h> #define all(x) x.begin(), x.end() #define rall(x) x.rbegin(), x.rend() //#define int long long using namespace std; using ll = long long; using pii = pair<int, int>; using pll = pair<ll, ll>; const int mod = 1e9 + 7; const int LOG = 20; const int maxn = 1e5 + 5; bool dp[51][1005][1005]; signed main() { int n; cin >> n; ll sum = 0; vector<int> v(n+1); for(int i=1; i<=n; i++) cin >> v[i], sum += v[i]; dp[0][0][0] = 1; for(int i=1; i<=n; i++) { for(int j=0; j<=sum; j++) { for(int k=0; k<=sum-j; k++) { dp[i][j][k] = dp[i-1][j][k]; if(v[i] <= j && dp[i-1][j-v[i]][k]) dp[i][j][k] = 1; if(v[i] <= k && dp[i-1][j][k-v[i]]) dp[i][j][k] = 1; } } } ll ans = 0; for(int i=0; i<=sum; i++) if(dp[n][i][i]) ans = i + (sum - 2 * i); cout << ans << '\n'; 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...