제출 #442981

#제출 시각아이디문제언어결과실행 시간메모리
442981zxcvbnmKas (COCI17_kas)C++14
70 / 100
63 ms83780 KiB
#include <bits/stdc++.h> using namespace std; using ll = long long; const int maxS = 1e5 + 5; const int INF = 1e9 + 5; int dp[105][maxS]; vector<int> a; int n; int go(int k, int diff) { if (dp[k][diff] != -1) { return dp[k][diff]; } int& ret = dp[k][diff]; if (k == n) { return ret = (diff == 0 ? 0 : -INF); } return ret = max({go(k+1, diff), go(k+1, diff+a[k])+a[k], go(k+1, abs(diff-a[k]))+a[k]}); } int main() { ios_base::sync_with_stdio(false); cin.tie(nullptr); memset(dp, -1, sizeof dp); cin >> n; a.resize(n); for(int i = 0; i < n; i++) { cin >> a[i]; } int sum = accumulate(a.begin(), a.end(), 0); int sol = go(0, 0); // cout << sol << "\n"; cout << (sol / 2) + (sum - (sol)); }
#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...