Submission #959584

#TimeUsernameProblemLanguageResultExecution timeMemory
959584Beerus13Kas (COCI17_kas)C++14
100 / 100
110 ms1244 KiB
#include<bits/stdc++.h> using namespace std; #define ll long long const int N = 1e5 + 5; bool maximize(int &a, int b) { if(a >= b) return true; a = b; return false; } int n; int dp[2][N]; void solve() { cin >> n; int cur = 0; memset(dp[cur], -0x3f, sizeof(dp[cur])); dp[cur][0] = 0; int sum = 0; for(int i = 1, x; i <= n; ++i) { cin >> x; sum += x; cur ^= 1; memset(dp[cur], -0x3f, sizeof(dp[cur])); for(int diff = 0; diff < N; ++diff) { maximize(dp[cur][diff], dp[cur ^ 1][diff]); if(diff + x < N) maximize(dp[cur][diff + x], dp[cur ^ 1][diff] + x); if(diff >= x) maximize(dp[cur][diff - x], dp[cur ^ 1][diff]); if(x >= diff) maximize(dp[cur][x - diff], dp[cur ^ 1][diff] + x - diff); } } cout << sum - dp[cur][0] << '\n'; } signed main() { ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); int test = 1; // cin >> test; while(test--) solve(); 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...