Submission #791102

# Submission time Handle Problem Language Result Execution time Memory
791102 2023-07-23T12:14:53 Z max0000561 Ants and Sugar (JOI22_sugar) C++17
6 / 100
4000 ms 1732 KB
#include<bits/stdc++.h>
#define int long long
#define sz(a) (int)a.size()

using namespace std;

signed main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    int q, L;
    cin >> q >> L;
    int Q = 0;
    vector<pair<int, int>> m, s;
    while (q--) {
        ++Q;
        int t, x, a;
        cin >> t >> x >> a;
        if (t == 1) {
            m.push_back({x, a});
        }
        else {
            s.push_back({x, a});
        }
        vector<pair<int, int>> M = m, S = s;
        sort(M.begin(), M.end());
        sort(S.begin(), S.end());
        int r = 0, ans = 0;
        for (int i = 0; i < sz(M); ++i) {
            while (r < sz(S) && M[i].first - S[r].first > L) {
                ++r;
            }
            if (r == sz(S)) break;
            while (r < sz(S) && abs(S[r].first - M[i].first) <= L) {
                if (M[i].second > S[r].second) {
                    ans += S[r].second;
                    M[i].second -= S[r].second;
                    S[r].second = 0;
                    ++r;
                }
                else {
                    ans += M[i].second;
                    S[r].second -= M[i].second;
                    M[i].second = 0;
                    break;
                }
            }
        }
        cout << ans << '\n';
    }
}
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 89 ms 456 KB Output is correct
7 Correct 63 ms 436 KB Output is correct
8 Correct 17 ms 444 KB Output is correct
9 Correct 14 ms 340 KB Output is correct
10 Correct 199 ms 612 KB Output is correct
11 Correct 198 ms 500 KB Output is correct
12 Correct 200 ms 468 KB Output is correct
13 Correct 199 ms 468 KB Output is correct
14 Correct 204 ms 612 KB Output is correct
15 Correct 201 ms 476 KB Output is correct
16 Correct 208 ms 536 KB Output is correct
17 Correct 204 ms 468 KB Output is correct
18 Correct 202 ms 468 KB Output is correct
19 Correct 196 ms 484 KB Output is correct
20 Correct 199 ms 512 KB Output is correct
21 Correct 195 ms 540 KB Output is correct
22 Correct 202 ms 452 KB Output is correct
23 Correct 195 ms 524 KB Output is correct
24 Correct 201 ms 460 KB Output is correct
25 Correct 195 ms 488 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Execution timed out 4075 ms 968 KB Time limit exceeded
5 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Execution timed out 4054 ms 1732 KB Time limit exceeded
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 89 ms 456 KB Output is correct
7 Correct 63 ms 436 KB Output is correct
8 Correct 17 ms 444 KB Output is correct
9 Correct 14 ms 340 KB Output is correct
10 Correct 199 ms 612 KB Output is correct
11 Correct 198 ms 500 KB Output is correct
12 Correct 200 ms 468 KB Output is correct
13 Correct 199 ms 468 KB Output is correct
14 Correct 204 ms 612 KB Output is correct
15 Correct 201 ms 476 KB Output is correct
16 Correct 208 ms 536 KB Output is correct
17 Correct 204 ms 468 KB Output is correct
18 Correct 202 ms 468 KB Output is correct
19 Correct 196 ms 484 KB Output is correct
20 Correct 199 ms 512 KB Output is correct
21 Correct 195 ms 540 KB Output is correct
22 Correct 202 ms 452 KB Output is correct
23 Correct 195 ms 524 KB Output is correct
24 Correct 201 ms 460 KB Output is correct
25 Correct 195 ms 488 KB Output is correct
26 Correct 1 ms 212 KB Output is correct
27 Correct 0 ms 212 KB Output is correct
28 Correct 0 ms 212 KB Output is correct
29 Execution timed out 4075 ms 968 KB Time limit exceeded
30 Halted 0 ms 0 KB -