Submission #244858

# Submission time Handle Problem Language Result Execution time Memory
244858 2020-07-05T07:43:39 Z Vladikus004 Kas (COCI17_kas) C++14
60 / 100
10 ms 384 KB
#include <bits/stdc++.h>
#define inf 2e9
#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 = 500, MAX = 1003;
int n, is[MAX], p[MAX], nis[MAX];
multiset <int> a;

bool try_without(int x){
    int X = x;
    vector <int> drop;
    while (x){
        drop.push_back(p[x]);
        x -= p[x];
    }
    for (auto u: drop)
        a.erase(a.lower_bound(u));
    for (int i = 0; i <= 1000; i++) nis[i] = 0;
    nis[0] = 1;
    for (auto u: a)
    for (int i = 1000; i >= u; i--){
        if (nis[i - u]) nis[i] = 1;
    }
    for (auto u: drop)
        a.insert(u);
    return nis[X];
}

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    #ifdef LOCAL
        freopen("input.txt", "r", stdin);
    #endif // LOCAL
    cin >> n;
    int sum = 0;
    is[0] = 1;
    for (int i = 0; i < n; i++){
        int x;
        cin >> x;
        a.insert(x);
        sum += x;
        for (int j = 1000; j >= x; j--){
            if (is[j - x] && !is[j]) {
                is[j] = 1;
                p[j] = x;
            }
        }
    }
    for (int i = 500; i > 0; i--){
        if (is[i]){
            if (try_without(i)){
                cout << i + sum - i * 2;
                return 0;
            }
        }
    }
    cout << sum;
}
# Verdict Execution time Memory Grader output
1 Correct 5 ms 384 KB Output is correct
2 Correct 5 ms 384 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 6 ms 384 KB Output is correct
2 Correct 6 ms 384 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 5 ms 384 KB Output is correct
2 Correct 4 ms 384 KB Output is correct
# Verdict Execution time Memory Grader output
1 Incorrect 6 ms 384 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 5 ms 384 KB Output is correct
2 Correct 4 ms 384 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 6 ms 384 KB Output is correct
2 Correct 8 ms 384 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 10 ms 384 KB Output is correct
2 Correct 8 ms 384 KB Output is correct
# Verdict Execution time Memory Grader output
1 Incorrect 5 ms 384 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 5 ms 384 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 5 ms 384 KB Output isn't correct
2 Halted 0 ms 0 KB -