# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
1042898 |
2024-08-03T14:17:25 Z |
VMaksimoski008 |
Kas (COCI17_kas) |
C++17 |
|
1 ms |
604 KB |
#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
kas.cpp: In function 'int main()':
kas.cpp:38:8: warning: unused variable 'ans' [-Wunused-variable]
38 | ll ans = 0;
| ^~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
348 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
0 ms |
348 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
1 ms |
348 KB |
Execution killed with signal 11 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
0 ms |
348 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
0 ms |
348 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
348 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
1 ms |
604 KB |
Execution killed with signal 11 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
1 ms |
604 KB |
Execution killed with signal 11 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
1 ms |
604 KB |
Execution killed with signal 11 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
1 ms |
604 KB |
Execution killed with signal 11 |
2 |
Halted |
0 ms |
0 KB |
- |