Submission #245106

# Submission time Handle Problem Language Result Execution time Memory
245106 2020-07-05T13:46:45 Z Vladikus004 Kas (COCI17_kas) C++14
0 / 100
335 ms 159224 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 + 5;
int n, a[N], dp[N][MAX], was[N][MAX], sum;

int get_ans(int ind, int diff){
    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 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 512 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 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 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 1024 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 5 ms 1280 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 126 ms 63584 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 164 ms 67556 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 335 ms 159224 KB Output isn't correct
2 Halted 0 ms 0 KB -