Submission #109008

#TimeUsernameProblemLanguageResultExecution timeMemory
109008bibabasKas (COCI17_kas)C++14
90 / 100
465 ms391928 KiB
#ifdef LOCAL #define _GLIBCXX_DEBUG #endif #include <bits/stdc++.h> #define ll long long #define vi vector<int> #define vvi vector<vi> #define all(x) x.begin(), x.end() #define pb push_back #define mp make_pair int INF = (int)2e9; using namespace std; template <class T> istream& operator >>(istream &in, vector<T> &arr) { for (T &cnt : arr) { in >> cnt; } return in; }; int n; int dp[500][(int)1e5 + 1]; vi num; int kek(int pos, int sum){ if (pos == n && sum == 0) return 0; if (pos == n) return -INF; if (dp[pos][sum] != -1) return dp[pos][sum]; int a = kek(pos + 1, sum); int b = num[pos] + kek(pos + 1, sum + num[pos]); int c = kek(pos + 1, sum - num[pos]); dp[pos][sum] = max({a, b, c}); return dp[pos][sum]; } void solve() { cin >> n; num.assign(n, 0); cin >> num; for (int i = 0; i <= n; ++i){ for (int j = 0; j <= (int)1e5; ++j){ dp[i][j] = -1; } } int sum = 0; for (int i = 0; i < n; ++i){ sum += num[i]; } cout << sum - kek(0, 0); } int main() { #ifdef LOCAL freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout); #else ios_base::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr); #endif 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...