Submission #348889

# Submission time Handle Problem Language Result Execution time Memory
348889 2021-01-16T04:06:43 Z ijxjdjd Two Dishes (JOI19_dishes) C++14
100 / 100
5409 ms 263264 KB
#include <bits/stdc++.h>
#define FR(i, N) for (int i = 0; i < int(N); i++)
using namespace std;

using ll = long long;
const int MAXN = (int)(1e6)+5;
ll A[MAXN];
ll S[MAXN];
ll B[MAXN];
ll T[MAXN];
ll P[MAXN];
ll Q[MAXN];
ll prefA[MAXN];
ll prefB[MAXN];
ll lzy[4*MAXN];
ll mx[4*MAXN];
void push(int n) {
    lzy[2*n] += lzy[n];
    lzy[2*n+1] += lzy[n];
    mx[2*n] += lzy[n];
    mx[2*n+1] += lzy[n];
    lzy[n] = 0;
}
void add(int n, int tl, int tr, int l, int r, ll ad) {
    if (tr < l || r < tl) {
        return;
    }
    if (l <= tl && tr <= r) {
        lzy[n] += ad;
        mx[n] += ad;
    }
    else {
        push(n);
        int tm = (tl + tr)/2;
        add(2*n, tl, tm, l, r, ad);
        add(2*n+1, tm+1, tr, l, r, ad);
        mx[n] = max(mx[2*n], mx[2*n+1]);
    }
}
ll query(int n, int tl, int tr, int l, int r) {
   if (tr < l || r < tl) {
        return ll(-1e18);
    }
    if (l <= tl && tr <= r) {
        return mx[n];
    }
    else {
        push(n);
        int tm = (tl + tr)/2;
        return max(query(2*n, tl, tm, l, r), query(2*n+1, tm+1, tr, l, r));
    }
}
void upd(int n, int tl, int tr, int i, ll val) {
    if (tl == tr) {
        mx[n] = max(mx[n], val);
        lzy[n] = 0;
    }
    else {
        push(n);
        int tm = (tl + tr)/2;
        if (i <= tm) {
            upd(2*n, tl, tm, i, val);
        }
        else {
            upd(2*n+1, tm+1, tr, i, val);
        }
        mx[n] = max(mx[2*n], mx[2*n+1]);
    }
}
vector<pair<int, ll>> row[MAXN];
int main() {
	cin.tie(0);
	cin.sync_with_stdio(0);
	int N, M;
	cin >> N >> M;
	FR(i, 4*MAXN) {
        mx[i] = (ll)(-1e18);
	}
	for (int i = 1; i <= N; i++) {
        cin >> A[i] >> S[i] >> P[i];
        prefA[i] = A[i] + prefA[i-1];
	}
	for (int i = 1; i <= M; i++) {
        cin >> B[i] >> T[i] >> Q[i];
        prefB[i] = B[i] + prefB[i-1];
	}
	ll offset = 0;
	for (int i = 1; i <= N; i++) {
        if (prefA[i] <= S[i]) {
            int low = 0;
            int high = M;
            ll g = S[i] - prefA[i];
            while (low < high) {
                int mid = (low + high+1)/2;
                if (prefB[mid] <= g) {
                    low = mid;
                }
                else {
                    high = mid-1;
                }
            }
            row[i].push_back({low, P[i]});
        }
	}
	for (int i = 1; i <= M; i++) {
        if (prefB[i] <= T[i]) {
            int low = 0;
            int high = N;
            ll g = T[i] - prefB[i];
            while (low < high) {
                int mid = (low + high+1)/2;
                if (prefA[mid] <= g) {
                    low = mid;
                }
                else {
                    high = mid-1;
                }
            }
            offset += Q[i];
            if (low != N) {
                row[low+1].push_back({i-1, -Q[i]});
            }
        }
	}
	upd(1, 0, M, 0, 0);
	FR(i, N+1) {
        sort(row[i].begin(), row[i].end());
        while (row[i].size()) {
            while (row[i].size() != 1) {
                if (row[i][row[i].size()-1].first == row[i][row[i].size()-2].first) {
                    row[i][row[i].size()-2].second += row[i][row[i].size()-1].second;
                    row[i].pop_back();
                }
                else {
                    break;
                }
            }
            upd(1, 0, M, row[i].back().first+1, query(1, 0, M, 0, row[i].back().first));
            add(1, 0, M, 0, row[i].back().first, row[i].back().second);
            row[i].pop_back();
        }
	}
	cout << mx[1] + offset;
	return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 446 ms 81644 KB Output is correct
2 Correct 444 ms 81516 KB Output is correct
3 Correct 265 ms 74092 KB Output is correct
4 Correct 344 ms 76012 KB Output is correct
5 Correct 35 ms 55148 KB Output is correct
6 Correct 417 ms 79852 KB Output is correct
7 Correct 122 ms 61676 KB Output is correct
8 Correct 138 ms 67692 KB Output is correct
9 Correct 269 ms 74092 KB Output is correct
10 Correct 370 ms 81388 KB Output is correct
11 Correct 235 ms 74000 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 35 ms 55148 KB Output is correct
2 Correct 34 ms 55276 KB Output is correct
3 Correct 35 ms 55168 KB Output is correct
4 Correct 35 ms 55148 KB Output is correct
5 Correct 35 ms 55148 KB Output is correct
6 Correct 35 ms 55148 KB Output is correct
7 Correct 34 ms 55148 KB Output is correct
8 Correct 34 ms 55148 KB Output is correct
9 Correct 35 ms 55148 KB Output is correct
10 Correct 40 ms 55148 KB Output is correct
11 Correct 34 ms 55148 KB Output is correct
12 Correct 35 ms 55148 KB Output is correct
13 Correct 35 ms 55148 KB Output is correct
14 Correct 35 ms 55148 KB Output is correct
15 Correct 36 ms 55148 KB Output is correct
16 Correct 35 ms 55148 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 35 ms 55148 KB Output is correct
2 Correct 34 ms 55276 KB Output is correct
3 Correct 35 ms 55168 KB Output is correct
4 Correct 35 ms 55148 KB Output is correct
5 Correct 35 ms 55148 KB Output is correct
6 Correct 35 ms 55148 KB Output is correct
7 Correct 34 ms 55148 KB Output is correct
8 Correct 34 ms 55148 KB Output is correct
9 Correct 35 ms 55148 KB Output is correct
10 Correct 40 ms 55148 KB Output is correct
11 Correct 34 ms 55148 KB Output is correct
12 Correct 35 ms 55148 KB Output is correct
13 Correct 35 ms 55148 KB Output is correct
14 Correct 35 ms 55148 KB Output is correct
15 Correct 36 ms 55148 KB Output is correct
16 Correct 35 ms 55148 KB Output is correct
17 Correct 38 ms 55404 KB Output is correct
18 Correct 37 ms 55404 KB Output is correct
19 Correct 40 ms 55532 KB Output is correct
20 Correct 39 ms 55404 KB Output is correct
21 Correct 38 ms 55404 KB Output is correct
22 Correct 38 ms 55532 KB Output is correct
23 Correct 38 ms 55532 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 35 ms 55148 KB Output is correct
2 Correct 34 ms 55276 KB Output is correct
3 Correct 35 ms 55168 KB Output is correct
4 Correct 35 ms 55148 KB Output is correct
5 Correct 35 ms 55148 KB Output is correct
6 Correct 35 ms 55148 KB Output is correct
7 Correct 34 ms 55148 KB Output is correct
8 Correct 34 ms 55148 KB Output is correct
9 Correct 35 ms 55148 KB Output is correct
10 Correct 40 ms 55148 KB Output is correct
11 Correct 34 ms 55148 KB Output is correct
12 Correct 35 ms 55148 KB Output is correct
13 Correct 35 ms 55148 KB Output is correct
14 Correct 35 ms 55148 KB Output is correct
15 Correct 36 ms 55148 KB Output is correct
16 Correct 35 ms 55148 KB Output is correct
17 Correct 38 ms 55404 KB Output is correct
18 Correct 37 ms 55404 KB Output is correct
19 Correct 40 ms 55532 KB Output is correct
20 Correct 39 ms 55404 KB Output is correct
21 Correct 38 ms 55404 KB Output is correct
22 Correct 38 ms 55532 KB Output is correct
23 Correct 38 ms 55532 KB Output is correct
24 Correct 350 ms 74092 KB Output is correct
25 Correct 401 ms 78292 KB Output is correct
26 Correct 367 ms 78188 KB Output is correct
27 Correct 398 ms 79852 KB Output is correct
28 Correct 390 ms 79084 KB Output is correct
29 Correct 239 ms 74092 KB Output is correct
30 Correct 822 ms 83436 KB Output is correct
31 Correct 196 ms 67428 KB Output is correct
32 Correct 127 ms 67692 KB Output is correct
33 Correct 498 ms 77512 KB Output is correct
34 Correct 661 ms 82156 KB Output is correct
35 Correct 784 ms 83692 KB Output is correct
36 Correct 766 ms 83436 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 35 ms 55148 KB Output is correct
2 Correct 34 ms 55276 KB Output is correct
3 Correct 35 ms 55168 KB Output is correct
4 Correct 35 ms 55148 KB Output is correct
5 Correct 35 ms 55148 KB Output is correct
6 Correct 35 ms 55148 KB Output is correct
7 Correct 34 ms 55148 KB Output is correct
8 Correct 34 ms 55148 KB Output is correct
9 Correct 35 ms 55148 KB Output is correct
10 Correct 40 ms 55148 KB Output is correct
11 Correct 34 ms 55148 KB Output is correct
12 Correct 35 ms 55148 KB Output is correct
13 Correct 35 ms 55148 KB Output is correct
14 Correct 35 ms 55148 KB Output is correct
15 Correct 36 ms 55148 KB Output is correct
16 Correct 35 ms 55148 KB Output is correct
17 Correct 38 ms 55404 KB Output is correct
18 Correct 37 ms 55404 KB Output is correct
19 Correct 40 ms 55532 KB Output is correct
20 Correct 39 ms 55404 KB Output is correct
21 Correct 38 ms 55404 KB Output is correct
22 Correct 38 ms 55532 KB Output is correct
23 Correct 38 ms 55532 KB Output is correct
24 Correct 350 ms 74092 KB Output is correct
25 Correct 401 ms 78292 KB Output is correct
26 Correct 367 ms 78188 KB Output is correct
27 Correct 398 ms 79852 KB Output is correct
28 Correct 390 ms 79084 KB Output is correct
29 Correct 239 ms 74092 KB Output is correct
30 Correct 822 ms 83436 KB Output is correct
31 Correct 196 ms 67428 KB Output is correct
32 Correct 127 ms 67692 KB Output is correct
33 Correct 498 ms 77512 KB Output is correct
34 Correct 661 ms 82156 KB Output is correct
35 Correct 784 ms 83692 KB Output is correct
36 Correct 766 ms 83436 KB Output is correct
37 Correct 400 ms 78060 KB Output is correct
38 Correct 425 ms 79724 KB Output is correct
39 Correct 398 ms 81260 KB Output is correct
40 Correct 397 ms 81260 KB Output is correct
41 Correct 35 ms 55148 KB Output is correct
42 Correct 836 ms 83436 KB Output is correct
43 Correct 505 ms 77420 KB Output is correct
44 Correct 699 ms 82028 KB Output is correct
45 Correct 805 ms 83564 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 35 ms 55148 KB Output is correct
2 Correct 34 ms 55276 KB Output is correct
3 Correct 35 ms 55168 KB Output is correct
4 Correct 35 ms 55148 KB Output is correct
5 Correct 35 ms 55148 KB Output is correct
6 Correct 35 ms 55148 KB Output is correct
7 Correct 34 ms 55148 KB Output is correct
8 Correct 34 ms 55148 KB Output is correct
9 Correct 35 ms 55148 KB Output is correct
10 Correct 40 ms 55148 KB Output is correct
11 Correct 34 ms 55148 KB Output is correct
12 Correct 35 ms 55148 KB Output is correct
13 Correct 35 ms 55148 KB Output is correct
14 Correct 35 ms 55148 KB Output is correct
15 Correct 36 ms 55148 KB Output is correct
16 Correct 35 ms 55148 KB Output is correct
17 Correct 38 ms 55404 KB Output is correct
18 Correct 37 ms 55404 KB Output is correct
19 Correct 40 ms 55532 KB Output is correct
20 Correct 39 ms 55404 KB Output is correct
21 Correct 38 ms 55404 KB Output is correct
22 Correct 38 ms 55532 KB Output is correct
23 Correct 38 ms 55532 KB Output is correct
24 Correct 350 ms 74092 KB Output is correct
25 Correct 401 ms 78292 KB Output is correct
26 Correct 367 ms 78188 KB Output is correct
27 Correct 398 ms 79852 KB Output is correct
28 Correct 390 ms 79084 KB Output is correct
29 Correct 239 ms 74092 KB Output is correct
30 Correct 822 ms 83436 KB Output is correct
31 Correct 196 ms 67428 KB Output is correct
32 Correct 127 ms 67692 KB Output is correct
33 Correct 498 ms 77512 KB Output is correct
34 Correct 661 ms 82156 KB Output is correct
35 Correct 784 ms 83692 KB Output is correct
36 Correct 766 ms 83436 KB Output is correct
37 Correct 400 ms 78060 KB Output is correct
38 Correct 425 ms 79724 KB Output is correct
39 Correct 398 ms 81260 KB Output is correct
40 Correct 397 ms 81260 KB Output is correct
41 Correct 35 ms 55148 KB Output is correct
42 Correct 836 ms 83436 KB Output is correct
43 Correct 505 ms 77420 KB Output is correct
44 Correct 699 ms 82028 KB Output is correct
45 Correct 805 ms 83564 KB Output is correct
46 Correct 1960 ms 165716 KB Output is correct
47 Correct 2134 ms 173420 KB Output is correct
48 Correct 1967 ms 181408 KB Output is correct
49 Correct 1979 ms 181356 KB Output is correct
50 Correct 5329 ms 192620 KB Output is correct
51 Correct 2903 ms 158996 KB Output is correct
52 Correct 3798 ms 181436 KB Output is correct
53 Correct 4852 ms 191212 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 446 ms 81644 KB Output is correct
2 Correct 444 ms 81516 KB Output is correct
3 Correct 265 ms 74092 KB Output is correct
4 Correct 344 ms 76012 KB Output is correct
5 Correct 35 ms 55148 KB Output is correct
6 Correct 417 ms 79852 KB Output is correct
7 Correct 122 ms 61676 KB Output is correct
8 Correct 138 ms 67692 KB Output is correct
9 Correct 269 ms 74092 KB Output is correct
10 Correct 370 ms 81388 KB Output is correct
11 Correct 235 ms 74000 KB Output is correct
12 Correct 35 ms 55148 KB Output is correct
13 Correct 34 ms 55276 KB Output is correct
14 Correct 35 ms 55168 KB Output is correct
15 Correct 35 ms 55148 KB Output is correct
16 Correct 35 ms 55148 KB Output is correct
17 Correct 35 ms 55148 KB Output is correct
18 Correct 34 ms 55148 KB Output is correct
19 Correct 34 ms 55148 KB Output is correct
20 Correct 35 ms 55148 KB Output is correct
21 Correct 40 ms 55148 KB Output is correct
22 Correct 34 ms 55148 KB Output is correct
23 Correct 35 ms 55148 KB Output is correct
24 Correct 35 ms 55148 KB Output is correct
25 Correct 35 ms 55148 KB Output is correct
26 Correct 36 ms 55148 KB Output is correct
27 Correct 35 ms 55148 KB Output is correct
28 Correct 38 ms 55404 KB Output is correct
29 Correct 37 ms 55404 KB Output is correct
30 Correct 40 ms 55532 KB Output is correct
31 Correct 39 ms 55404 KB Output is correct
32 Correct 38 ms 55404 KB Output is correct
33 Correct 38 ms 55532 KB Output is correct
34 Correct 38 ms 55532 KB Output is correct
35 Correct 350 ms 74092 KB Output is correct
36 Correct 401 ms 78292 KB Output is correct
37 Correct 367 ms 78188 KB Output is correct
38 Correct 398 ms 79852 KB Output is correct
39 Correct 390 ms 79084 KB Output is correct
40 Correct 239 ms 74092 KB Output is correct
41 Correct 822 ms 83436 KB Output is correct
42 Correct 196 ms 67428 KB Output is correct
43 Correct 127 ms 67692 KB Output is correct
44 Correct 498 ms 77512 KB Output is correct
45 Correct 661 ms 82156 KB Output is correct
46 Correct 784 ms 83692 KB Output is correct
47 Correct 766 ms 83436 KB Output is correct
48 Correct 400 ms 78060 KB Output is correct
49 Correct 425 ms 79724 KB Output is correct
50 Correct 398 ms 81260 KB Output is correct
51 Correct 397 ms 81260 KB Output is correct
52 Correct 35 ms 55148 KB Output is correct
53 Correct 836 ms 83436 KB Output is correct
54 Correct 505 ms 77420 KB Output is correct
55 Correct 699 ms 82028 KB Output is correct
56 Correct 805 ms 83564 KB Output is correct
57 Correct 402 ms 78188 KB Output is correct
58 Correct 434 ms 79724 KB Output is correct
59 Correct 403 ms 81260 KB Output is correct
60 Correct 405 ms 81260 KB Output is correct
61 Correct 830 ms 83692 KB Output is correct
62 Correct 35 ms 55148 KB Output is correct
63 Correct 830 ms 83564 KB Output is correct
64 Correct 508 ms 77448 KB Output is correct
65 Correct 671 ms 81516 KB Output is correct
66 Correct 763 ms 90988 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 446 ms 81644 KB Output is correct
2 Correct 444 ms 81516 KB Output is correct
3 Correct 265 ms 74092 KB Output is correct
4 Correct 344 ms 76012 KB Output is correct
5 Correct 35 ms 55148 KB Output is correct
6 Correct 417 ms 79852 KB Output is correct
7 Correct 122 ms 61676 KB Output is correct
8 Correct 138 ms 67692 KB Output is correct
9 Correct 269 ms 74092 KB Output is correct
10 Correct 370 ms 81388 KB Output is correct
11 Correct 235 ms 74000 KB Output is correct
12 Correct 35 ms 55148 KB Output is correct
13 Correct 34 ms 55276 KB Output is correct
14 Correct 35 ms 55168 KB Output is correct
15 Correct 35 ms 55148 KB Output is correct
16 Correct 35 ms 55148 KB Output is correct
17 Correct 35 ms 55148 KB Output is correct
18 Correct 34 ms 55148 KB Output is correct
19 Correct 34 ms 55148 KB Output is correct
20 Correct 35 ms 55148 KB Output is correct
21 Correct 40 ms 55148 KB Output is correct
22 Correct 34 ms 55148 KB Output is correct
23 Correct 35 ms 55148 KB Output is correct
24 Correct 35 ms 55148 KB Output is correct
25 Correct 35 ms 55148 KB Output is correct
26 Correct 36 ms 55148 KB Output is correct
27 Correct 35 ms 55148 KB Output is correct
28 Correct 38 ms 55404 KB Output is correct
29 Correct 37 ms 55404 KB Output is correct
30 Correct 40 ms 55532 KB Output is correct
31 Correct 39 ms 55404 KB Output is correct
32 Correct 38 ms 55404 KB Output is correct
33 Correct 38 ms 55532 KB Output is correct
34 Correct 38 ms 55532 KB Output is correct
35 Correct 350 ms 74092 KB Output is correct
36 Correct 401 ms 78292 KB Output is correct
37 Correct 367 ms 78188 KB Output is correct
38 Correct 398 ms 79852 KB Output is correct
39 Correct 390 ms 79084 KB Output is correct
40 Correct 239 ms 74092 KB Output is correct
41 Correct 822 ms 83436 KB Output is correct
42 Correct 196 ms 67428 KB Output is correct
43 Correct 127 ms 67692 KB Output is correct
44 Correct 498 ms 77512 KB Output is correct
45 Correct 661 ms 82156 KB Output is correct
46 Correct 784 ms 83692 KB Output is correct
47 Correct 766 ms 83436 KB Output is correct
48 Correct 400 ms 78060 KB Output is correct
49 Correct 425 ms 79724 KB Output is correct
50 Correct 398 ms 81260 KB Output is correct
51 Correct 397 ms 81260 KB Output is correct
52 Correct 35 ms 55148 KB Output is correct
53 Correct 836 ms 83436 KB Output is correct
54 Correct 505 ms 77420 KB Output is correct
55 Correct 699 ms 82028 KB Output is correct
56 Correct 805 ms 83564 KB Output is correct
57 Correct 1960 ms 165716 KB Output is correct
58 Correct 2134 ms 173420 KB Output is correct
59 Correct 1967 ms 181408 KB Output is correct
60 Correct 1979 ms 181356 KB Output is correct
61 Correct 5329 ms 192620 KB Output is correct
62 Correct 2903 ms 158996 KB Output is correct
63 Correct 3798 ms 181436 KB Output is correct
64 Correct 4852 ms 191212 KB Output is correct
65 Correct 402 ms 78188 KB Output is correct
66 Correct 434 ms 79724 KB Output is correct
67 Correct 403 ms 81260 KB Output is correct
68 Correct 405 ms 81260 KB Output is correct
69 Correct 830 ms 83692 KB Output is correct
70 Correct 35 ms 55148 KB Output is correct
71 Correct 830 ms 83564 KB Output is correct
72 Correct 508 ms 77448 KB Output is correct
73 Correct 671 ms 81516 KB Output is correct
74 Correct 763 ms 90988 KB Output is correct
75 Correct 2025 ms 237272 KB Output is correct
76 Correct 2198 ms 245072 KB Output is correct
77 Correct 2025 ms 239816 KB Output is correct
78 Correct 2025 ms 240108 KB Output is correct
79 Correct 5409 ms 263264 KB Output is correct
80 Correct 2906 ms 227440 KB Output is correct
81 Correct 3803 ms 243040 KB Output is correct
82 Correct 5029 ms 230864 KB Output is correct
83 Correct 4972 ms 248428 KB Output is correct