Submission #245105

# Submission time Handle Problem Language Result Execution time Memory
245105 2020-07-05T13:44:56 Z Vladikus004 Kas (COCI17_kas) C++14
20 / 100
253 ms 131964 KB
#include <bits/stdc++.h>
#define inf 2e9
#define int long long
#define all(v) v.begin(), v.end()
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair <int, int> pii;

const int N = 505, MAX = 100000;
int n, a[N], dp[N][MAX], was[N][MAX], sum;

int get_ans(int ind, int diff){
    if (diff > sum / 2)
        return -inf;

    if (was[ind][diff]) return dp[ind][diff];
    was[ind][diff] = 1;

    if (ind == n){
        if (diff == 0) return 0;
        return -inf;
    }

    dp[ind][diff] = max(get_ans(ind + 1, diff), max(get_ans(ind + 1, diff + a[ind]),
                  get_ans(ind + 1, abs(diff - a[ind]))) + a[ind]);

    return dp[ind][diff];
}

int32_t main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    #ifdef LOCAL
        freopen("input.txt", "r", stdin);
    #endif // LOCAL
    cin >> n;
    for (int i = 0; i < n; i++) {
        cin >> a[i];
        sum += a[i];
    }
    int ans = get_ans(0, 0);
//    cout << ans << "\n";
    cout << ans / 2 + sum - ans;
}
# Verdict Execution time Memory Grader output
1 Correct 5 ms 512 KB Output is correct
2 Correct 5 ms 512 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 5 ms 512 KB Output is correct
2 Incorrect 5 ms 512 KB Output isn't correct
# Verdict Execution time Memory Grader output
1 Correct 5 ms 512 KB Output is correct
2 Correct 5 ms 512 KB Output is correct
# Verdict Execution time Memory Grader output
1 Incorrect 5 ms 512 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 5 ms 640 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 5 ms 768 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 5 ms 1152 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 67 ms 34912 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 100 ms 42492 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 253 ms 131964 KB Output isn't correct
2 Halted 0 ms 0 KB -