Submission #1042905

# Submission time Handle Problem Language Result Execution time Memory
1042905 2024-08-03T14:31:09 Z VMaksimoski008 Kas (COCI17_kas) C++17
70 / 100
284 ms 325932 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 = 1e5 + 5;

int dp[205][2*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];
    for(int j=0; j<=2*maxn; j++) dp[0][j] = -1e9;
    dp[0][maxn] = 0;

    for(int i=1; i<=n; i++) {
        for(int j=0; j<=2*maxn; j++) {
            dp[i][j] = dp[i-1][j];
            if(j + v[i] <= 2 * maxn && dp[i-1][j+v[i]] >= 0) dp[i][j] = max(dp[i][j], dp[i-1][j+v[i]] + v[i]);
            if(j - v[i] >= 0 && dp[i-1][j-v[i]] >= 0) dp[i][j] = max(dp[i][j], dp[i-1][j-v[i]] + v[i]);
        }
    }

    cout << sum - dp[n][maxn] / 2 << '\n';
    return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 5 ms 9048 KB Output is correct
2 Correct 5 ms 9052 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 9 ms 9044 KB Output is correct
2 Correct 9 ms 9052 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 5 ms 9052 KB Output is correct
2 Correct 5 ms 9736 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 6 ms 10588 KB Output is correct
2 Correct 12 ms 11356 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 12 ms 11352 KB Output is correct
2 Correct 12 ms 11352 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 17 ms 28508 KB Output is correct
2 Correct 19 ms 32344 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 21 ms 36444 KB Output is correct
2 Correct 24 ms 40284 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 104 ms 157652 KB Output is correct
2 Runtime error 244 ms 325744 KB Execution killed with signal 11
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 198 ms 325932 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 284 ms 325784 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -