Submission #1042898

#TimeUsernameProblemLanguageResultExecution timeMemory
1042898VMaksimoski008Kas (COCI17_kas)C++17
0 / 100
1 ms604 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 = 100 + 5; int dp[205][maxn+5]; 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][maxn/2] = 0; for(int i=0; i<n; i++) { for(int j=-50; j<=50; j++) { int val = maxn/2 + j; dp[i+1][val] = max(dp[i+1][val], dp[i][val]); if(val + v[i] <= maxn) dp[i+1][val+v[i]] = max(dp[i+1][val+v[i]], dp[i][val] + v[i]); if(val - v[i] <= maxn) dp[i+1][val-v[i]] = max(dp[i+1][val-v[i]], dp[i][val] + v[i]); // cout << i+1 << " " << j << ": " << dp[i+1][val] << '\n'; } } ll ans = 0; cout << dp[n][maxn/2] << '\n'; // cout << ans << '\n'; return 0; }

Compilation message (stderr)

kas.cpp: In function 'int main()':
kas.cpp:38:8: warning: unused variable 'ans' [-Wunused-variable]
   38 |     ll ans = 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...