Submission #873393

# Submission time Handle Problem Language Result Execution time Memory
873393 2023-11-15T02:24:56 Z vjudge1 Kas (COCI17_kas) C++17
100 / 100
141 ms 98652 KB
#include<bits/stdc++.h>
using namespace std;
const int N=1e5+7, inf=1e9+7;
int n, a[N], s;
int f[502][N/2];
int calc(int k, int diff)
{
    if (diff > s/2) return -1e9;
    if (k == n+1)
    {
        if (diff) return -1e9;
        return 0;
    }
    if (f[k][diff]!=-1) return f[k][diff];
    return f[k][diff] = max({calc(k+1, diff),
                             calc(k+1, abs(diff-a[k])) + min(a[k], diff),
                             calc(k+1, diff+a[k])});
}
int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);

    cin >> n;
    for(int i=1; i<=n; ++i) cin >> a[i], s+=a[i];
    memset(f, -1, sizeof f);
    int ans = calc(1, 0);
    ans += s - 2*ans;
    cout << ans;
}
# Verdict Execution time Memory Grader output
1 Correct 12 ms 98652 KB Output is correct
2 Correct 15 ms 98652 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 13 ms 98652 KB Output is correct
2 Correct 14 ms 98652 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 14 ms 98648 KB Output is correct
2 Correct 12 ms 98648 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 12 ms 98616 KB Output is correct
2 Correct 13 ms 98648 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 12 ms 98568 KB Output is correct
2 Correct 13 ms 98652 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 12 ms 98648 KB Output is correct
2 Correct 13 ms 98652 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 13 ms 98564 KB Output is correct
2 Correct 13 ms 98620 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 37 ms 98648 KB Output is correct
2 Correct 22 ms 98652 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 45 ms 98556 KB Output is correct
2 Correct 71 ms 98628 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 141 ms 98648 KB Output is correct
2 Correct 108 ms 98648 KB Output is correct