# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
1042899 |
2024-08-03T14:18:05 Z |
VMaksimoski008 |
Kas (COCI17_kas) |
C++17 |
|
15 ms |
16756 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 = 1e4 + 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=-maxn/2; j<=maxn/2; 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 |
604 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
0 ms |
604 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
604 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
860 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
860 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
1628 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
2 ms |
2392 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
8 ms |
8284 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
13 ms |
16728 KB |
Execution killed with signal 11 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
15 ms |
16756 KB |
Execution killed with signal 11 |
2 |
Halted |
0 ms |
0 KB |
- |