Submission #768335

# Submission time Handle Problem Language Result Execution time Memory
768335 2023-06-27T23:18:56 Z PurpleCrayon Distributing Candies (IOI21_candies) C++17
29 / 100
198 ms 24936 KB
#include "candies.h"
#include <bits/stdc++.h>
using namespace std;

#define sz(v) int(v.size())
#define ar array
typedef long long ll;


vector<int> distribute_candies(vector<int> c, vector<int> l, vector<int> r, vector<int> v) {
    int n = sz(c), q = sz(v);
    vector<int> a(c.begin(), c.end());
    sort(a.rbegin(), a.rend());

    vector<ll> ps(q);
    for (int i = 0; i < q; i++) {
        ps[i] = v[i];
        if (i) ps[i] += ps[i-1];
    }

    vector<ll> mn(q), mx(q);
    for (int i = q-1; i >= 0; i--) {
        mn[i] = mx[i] = ps[i];
        if (i < q-1) mn[i] = min(mn[i], mn[i+1]), mx[i] = max(mx[i], mx[i+1]);
    }

    map<int, ll> store;
    int last = -1;
    for (int x : a) {
        while (last < q-1) {
            ll cur = (last < 0 || v[last] < 0 ? 0 : x);
            ll cur_ps = last >= 0 ? ps[last] : 0;
            if (mn[last + 1] - cur_ps + cur < 0 || mx[last + 1] - cur_ps + cur >= x) {
                int use = last + 1;
                do {
                    cur += v[use++];
                } while (0 < cur && cur < x);
                last = use - 1;
            } else break;
        }

        ll cur = (last < 0 || v[last] < 0 ? 0 : x);
        ll cur_ps = last >= 0 ? ps[last] : 0;
        store[x] = ps.back() - cur_ps + cur;
    }

    vector<int> ans(n);
    for (int i = 0; i < n; i++)
        ans[i] = store[c[i]];

    return ans;
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Incorrect 1 ms 212 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 169 ms 24936 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 212 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 48 ms 12372 KB Output is correct
4 Correct 114 ms 11960 KB Output is correct
5 Correct 152 ms 21836 KB Output is correct
6 Correct 162 ms 24236 KB Output is correct
7 Correct 198 ms 24800 KB Output is correct
8 Correct 160 ms 21668 KB Output is correct
9 Correct 86 ms 17612 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Incorrect 1 ms 212 KB Output isn't correct
3 Halted 0 ms 0 KB -