답안 #348888

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
348888 2021-01-16T04:03:45 Z ijxjdjd Two Dishes (JOI19_dishes) C++14
74 / 100
5399 ms 193424 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, MAXN, 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, MAXN, row[i].back().first+1, query(1, 0, MAXN, 0, row[i].back().first));
            add(1, 0, MAXN, 0, row[i].back().first, row[i].back().second);
            row[i].pop_back();
        }
	}
	cout << mx[1] + offset;
	return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 505 ms 80748 KB Output is correct
2 Correct 481 ms 80876 KB Output is correct
3 Correct 406 ms 75500 KB Output is correct
4 Correct 378 ms 76684 KB Output is correct
5 Correct 35 ms 55404 KB Output is correct
6 Correct 475 ms 80408 KB Output is correct
7 Correct 120 ms 62956 KB Output is correct
8 Correct 303 ms 69228 KB Output is correct
9 Correct 404 ms 75244 KB Output is correct
10 Correct 394 ms 82084 KB Output is correct
11 Correct 351 ms 75372 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 34 ms 55276 KB Output is correct
2 Correct 36 ms 55276 KB Output is correct
3 Correct 35 ms 55276 KB Output is correct
4 Correct 37 ms 55276 KB Output is correct
5 Correct 34 ms 55276 KB Output is correct
6 Correct 35 ms 55276 KB Output is correct
7 Correct 35 ms 55276 KB Output is correct
8 Correct 35 ms 55276 KB Output is correct
9 Correct 34 ms 55276 KB Output is correct
10 Correct 35 ms 55276 KB Output is correct
11 Correct 34 ms 55276 KB Output is correct
12 Correct 34 ms 55276 KB Output is correct
13 Correct 35 ms 55276 KB Output is correct
14 Correct 35 ms 55276 KB Output is correct
15 Correct 35 ms 55276 KB Output is correct
16 Correct 36 ms 55276 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 34 ms 55276 KB Output is correct
2 Correct 36 ms 55276 KB Output is correct
3 Correct 35 ms 55276 KB Output is correct
4 Correct 37 ms 55276 KB Output is correct
5 Correct 34 ms 55276 KB Output is correct
6 Correct 35 ms 55276 KB Output is correct
7 Correct 35 ms 55276 KB Output is correct
8 Correct 35 ms 55276 KB Output is correct
9 Correct 34 ms 55276 KB Output is correct
10 Correct 35 ms 55276 KB Output is correct
11 Correct 34 ms 55276 KB Output is correct
12 Correct 34 ms 55276 KB Output is correct
13 Correct 35 ms 55276 KB Output is correct
14 Correct 35 ms 55276 KB Output is correct
15 Correct 35 ms 55276 KB Output is correct
16 Correct 36 ms 55276 KB Output is correct
17 Correct 38 ms 55660 KB Output is correct
18 Correct 39 ms 55660 KB Output is correct
19 Correct 41 ms 55660 KB Output is correct
20 Correct 38 ms 55660 KB Output is correct
21 Correct 47 ms 55660 KB Output is correct
22 Correct 40 ms 55532 KB Output is correct
23 Correct 41 ms 55532 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 34 ms 55276 KB Output is correct
2 Correct 36 ms 55276 KB Output is correct
3 Correct 35 ms 55276 KB Output is correct
4 Correct 37 ms 55276 KB Output is correct
5 Correct 34 ms 55276 KB Output is correct
6 Correct 35 ms 55276 KB Output is correct
7 Correct 35 ms 55276 KB Output is correct
8 Correct 35 ms 55276 KB Output is correct
9 Correct 34 ms 55276 KB Output is correct
10 Correct 35 ms 55276 KB Output is correct
11 Correct 34 ms 55276 KB Output is correct
12 Correct 34 ms 55276 KB Output is correct
13 Correct 35 ms 55276 KB Output is correct
14 Correct 35 ms 55276 KB Output is correct
15 Correct 35 ms 55276 KB Output is correct
16 Correct 36 ms 55276 KB Output is correct
17 Correct 38 ms 55660 KB Output is correct
18 Correct 39 ms 55660 KB Output is correct
19 Correct 41 ms 55660 KB Output is correct
20 Correct 38 ms 55660 KB Output is correct
21 Correct 47 ms 55660 KB Output is correct
22 Correct 40 ms 55532 KB Output is correct
23 Correct 41 ms 55532 KB Output is correct
24 Correct 373 ms 75500 KB Output is correct
25 Correct 471 ms 78804 KB Output is correct
26 Correct 393 ms 78700 KB Output is correct
27 Correct 487 ms 80236 KB Output is correct
28 Correct 489 ms 79852 KB Output is correct
29 Correct 392 ms 75500 KB Output is correct
30 Correct 854 ms 84076 KB Output is correct
31 Correct 205 ms 67428 KB Output is correct
32 Correct 291 ms 68716 KB Output is correct
33 Correct 520 ms 77952 KB Output is correct
34 Correct 764 ms 82668 KB Output is correct
35 Correct 840 ms 83692 KB Output is correct
36 Correct 804 ms 83308 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 34 ms 55276 KB Output is correct
2 Correct 36 ms 55276 KB Output is correct
3 Correct 35 ms 55276 KB Output is correct
4 Correct 37 ms 55276 KB Output is correct
5 Correct 34 ms 55276 KB Output is correct
6 Correct 35 ms 55276 KB Output is correct
7 Correct 35 ms 55276 KB Output is correct
8 Correct 35 ms 55276 KB Output is correct
9 Correct 34 ms 55276 KB Output is correct
10 Correct 35 ms 55276 KB Output is correct
11 Correct 34 ms 55276 KB Output is correct
12 Correct 34 ms 55276 KB Output is correct
13 Correct 35 ms 55276 KB Output is correct
14 Correct 35 ms 55276 KB Output is correct
15 Correct 35 ms 55276 KB Output is correct
16 Correct 36 ms 55276 KB Output is correct
17 Correct 38 ms 55660 KB Output is correct
18 Correct 39 ms 55660 KB Output is correct
19 Correct 41 ms 55660 KB Output is correct
20 Correct 38 ms 55660 KB Output is correct
21 Correct 47 ms 55660 KB Output is correct
22 Correct 40 ms 55532 KB Output is correct
23 Correct 41 ms 55532 KB Output is correct
24 Correct 373 ms 75500 KB Output is correct
25 Correct 471 ms 78804 KB Output is correct
26 Correct 393 ms 78700 KB Output is correct
27 Correct 487 ms 80236 KB Output is correct
28 Correct 489 ms 79852 KB Output is correct
29 Correct 392 ms 75500 KB Output is correct
30 Correct 854 ms 84076 KB Output is correct
31 Correct 205 ms 67428 KB Output is correct
32 Correct 291 ms 68716 KB Output is correct
33 Correct 520 ms 77952 KB Output is correct
34 Correct 764 ms 82668 KB Output is correct
35 Correct 840 ms 83692 KB Output is correct
36 Correct 804 ms 83308 KB Output is correct
37 Correct 415 ms 78572 KB Output is correct
38 Correct 560 ms 80236 KB Output is correct
39 Correct 422 ms 81968 KB Output is correct
40 Correct 413 ms 81772 KB Output is correct
41 Correct 35 ms 55276 KB Output is correct
42 Correct 915 ms 83948 KB Output is correct
43 Correct 524 ms 77548 KB Output is correct
44 Correct 780 ms 82300 KB Output is correct
45 Correct 842 ms 84332 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 34 ms 55276 KB Output is correct
2 Correct 36 ms 55276 KB Output is correct
3 Correct 35 ms 55276 KB Output is correct
4 Correct 37 ms 55276 KB Output is correct
5 Correct 34 ms 55276 KB Output is correct
6 Correct 35 ms 55276 KB Output is correct
7 Correct 35 ms 55276 KB Output is correct
8 Correct 35 ms 55276 KB Output is correct
9 Correct 34 ms 55276 KB Output is correct
10 Correct 35 ms 55276 KB Output is correct
11 Correct 34 ms 55276 KB Output is correct
12 Correct 34 ms 55276 KB Output is correct
13 Correct 35 ms 55276 KB Output is correct
14 Correct 35 ms 55276 KB Output is correct
15 Correct 35 ms 55276 KB Output is correct
16 Correct 36 ms 55276 KB Output is correct
17 Correct 38 ms 55660 KB Output is correct
18 Correct 39 ms 55660 KB Output is correct
19 Correct 41 ms 55660 KB Output is correct
20 Correct 38 ms 55660 KB Output is correct
21 Correct 47 ms 55660 KB Output is correct
22 Correct 40 ms 55532 KB Output is correct
23 Correct 41 ms 55532 KB Output is correct
24 Correct 373 ms 75500 KB Output is correct
25 Correct 471 ms 78804 KB Output is correct
26 Correct 393 ms 78700 KB Output is correct
27 Correct 487 ms 80236 KB Output is correct
28 Correct 489 ms 79852 KB Output is correct
29 Correct 392 ms 75500 KB Output is correct
30 Correct 854 ms 84076 KB Output is correct
31 Correct 205 ms 67428 KB Output is correct
32 Correct 291 ms 68716 KB Output is correct
33 Correct 520 ms 77952 KB Output is correct
34 Correct 764 ms 82668 KB Output is correct
35 Correct 840 ms 83692 KB Output is correct
36 Correct 804 ms 83308 KB Output is correct
37 Correct 415 ms 78572 KB Output is correct
38 Correct 560 ms 80236 KB Output is correct
39 Correct 422 ms 81968 KB Output is correct
40 Correct 413 ms 81772 KB Output is correct
41 Correct 35 ms 55276 KB Output is correct
42 Correct 915 ms 83948 KB Output is correct
43 Correct 524 ms 77548 KB Output is correct
44 Correct 780 ms 82300 KB Output is correct
45 Correct 842 ms 84332 KB Output is correct
46 Correct 2035 ms 166128 KB Output is correct
47 Correct 2482 ms 173944 KB Output is correct
48 Correct 1957 ms 181996 KB Output is correct
49 Correct 1941 ms 181996 KB Output is correct
50 Correct 5399 ms 193424 KB Output is correct
51 Correct 2945 ms 158940 KB Output is correct
52 Correct 4119 ms 179736 KB Output is correct
53 Correct 4967 ms 191100 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 505 ms 80748 KB Output is correct
2 Correct 481 ms 80876 KB Output is correct
3 Correct 406 ms 75500 KB Output is correct
4 Correct 378 ms 76684 KB Output is correct
5 Correct 35 ms 55404 KB Output is correct
6 Correct 475 ms 80408 KB Output is correct
7 Correct 120 ms 62956 KB Output is correct
8 Correct 303 ms 69228 KB Output is correct
9 Correct 404 ms 75244 KB Output is correct
10 Correct 394 ms 82084 KB Output is correct
11 Correct 351 ms 75372 KB Output is correct
12 Correct 34 ms 55276 KB Output is correct
13 Correct 36 ms 55276 KB Output is correct
14 Correct 35 ms 55276 KB Output is correct
15 Correct 37 ms 55276 KB Output is correct
16 Correct 34 ms 55276 KB Output is correct
17 Correct 35 ms 55276 KB Output is correct
18 Correct 35 ms 55276 KB Output is correct
19 Correct 35 ms 55276 KB Output is correct
20 Correct 34 ms 55276 KB Output is correct
21 Correct 35 ms 55276 KB Output is correct
22 Correct 34 ms 55276 KB Output is correct
23 Correct 34 ms 55276 KB Output is correct
24 Correct 35 ms 55276 KB Output is correct
25 Correct 35 ms 55276 KB Output is correct
26 Correct 35 ms 55276 KB Output is correct
27 Correct 36 ms 55276 KB Output is correct
28 Correct 38 ms 55660 KB Output is correct
29 Correct 39 ms 55660 KB Output is correct
30 Correct 41 ms 55660 KB Output is correct
31 Correct 38 ms 55660 KB Output is correct
32 Correct 47 ms 55660 KB Output is correct
33 Correct 40 ms 55532 KB Output is correct
34 Correct 41 ms 55532 KB Output is correct
35 Correct 373 ms 75500 KB Output is correct
36 Correct 471 ms 78804 KB Output is correct
37 Correct 393 ms 78700 KB Output is correct
38 Correct 487 ms 80236 KB Output is correct
39 Correct 489 ms 79852 KB Output is correct
40 Correct 392 ms 75500 KB Output is correct
41 Correct 854 ms 84076 KB Output is correct
42 Correct 205 ms 67428 KB Output is correct
43 Correct 291 ms 68716 KB Output is correct
44 Correct 520 ms 77952 KB Output is correct
45 Correct 764 ms 82668 KB Output is correct
46 Correct 840 ms 83692 KB Output is correct
47 Correct 804 ms 83308 KB Output is correct
48 Correct 415 ms 78572 KB Output is correct
49 Correct 560 ms 80236 KB Output is correct
50 Correct 422 ms 81968 KB Output is correct
51 Correct 413 ms 81772 KB Output is correct
52 Correct 35 ms 55276 KB Output is correct
53 Correct 915 ms 83948 KB Output is correct
54 Correct 524 ms 77548 KB Output is correct
55 Correct 780 ms 82300 KB Output is correct
56 Correct 842 ms 84332 KB Output is correct
57 Correct 429 ms 77264 KB Output is correct
58 Correct 528 ms 79212 KB Output is correct
59 Correct 422 ms 80704 KB Output is correct
60 Correct 427 ms 80620 KB Output is correct
61 Correct 888 ms 83052 KB Output is correct
62 Correct 35 ms 55276 KB Output is correct
63 Correct 895 ms 82796 KB Output is correct
64 Correct 539 ms 76652 KB Output is correct
65 Incorrect 731 ms 80748 KB Output isn't correct
66 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 505 ms 80748 KB Output is correct
2 Correct 481 ms 80876 KB Output is correct
3 Correct 406 ms 75500 KB Output is correct
4 Correct 378 ms 76684 KB Output is correct
5 Correct 35 ms 55404 KB Output is correct
6 Correct 475 ms 80408 KB Output is correct
7 Correct 120 ms 62956 KB Output is correct
8 Correct 303 ms 69228 KB Output is correct
9 Correct 404 ms 75244 KB Output is correct
10 Correct 394 ms 82084 KB Output is correct
11 Correct 351 ms 75372 KB Output is correct
12 Correct 34 ms 55276 KB Output is correct
13 Correct 36 ms 55276 KB Output is correct
14 Correct 35 ms 55276 KB Output is correct
15 Correct 37 ms 55276 KB Output is correct
16 Correct 34 ms 55276 KB Output is correct
17 Correct 35 ms 55276 KB Output is correct
18 Correct 35 ms 55276 KB Output is correct
19 Correct 35 ms 55276 KB Output is correct
20 Correct 34 ms 55276 KB Output is correct
21 Correct 35 ms 55276 KB Output is correct
22 Correct 34 ms 55276 KB Output is correct
23 Correct 34 ms 55276 KB Output is correct
24 Correct 35 ms 55276 KB Output is correct
25 Correct 35 ms 55276 KB Output is correct
26 Correct 35 ms 55276 KB Output is correct
27 Correct 36 ms 55276 KB Output is correct
28 Correct 38 ms 55660 KB Output is correct
29 Correct 39 ms 55660 KB Output is correct
30 Correct 41 ms 55660 KB Output is correct
31 Correct 38 ms 55660 KB Output is correct
32 Correct 47 ms 55660 KB Output is correct
33 Correct 40 ms 55532 KB Output is correct
34 Correct 41 ms 55532 KB Output is correct
35 Correct 373 ms 75500 KB Output is correct
36 Correct 471 ms 78804 KB Output is correct
37 Correct 393 ms 78700 KB Output is correct
38 Correct 487 ms 80236 KB Output is correct
39 Correct 489 ms 79852 KB Output is correct
40 Correct 392 ms 75500 KB Output is correct
41 Correct 854 ms 84076 KB Output is correct
42 Correct 205 ms 67428 KB Output is correct
43 Correct 291 ms 68716 KB Output is correct
44 Correct 520 ms 77952 KB Output is correct
45 Correct 764 ms 82668 KB Output is correct
46 Correct 840 ms 83692 KB Output is correct
47 Correct 804 ms 83308 KB Output is correct
48 Correct 415 ms 78572 KB Output is correct
49 Correct 560 ms 80236 KB Output is correct
50 Correct 422 ms 81968 KB Output is correct
51 Correct 413 ms 81772 KB Output is correct
52 Correct 35 ms 55276 KB Output is correct
53 Correct 915 ms 83948 KB Output is correct
54 Correct 524 ms 77548 KB Output is correct
55 Correct 780 ms 82300 KB Output is correct
56 Correct 842 ms 84332 KB Output is correct
57 Correct 2035 ms 166128 KB Output is correct
58 Correct 2482 ms 173944 KB Output is correct
59 Correct 1957 ms 181996 KB Output is correct
60 Correct 1941 ms 181996 KB Output is correct
61 Correct 5399 ms 193424 KB Output is correct
62 Correct 2945 ms 158940 KB Output is correct
63 Correct 4119 ms 179736 KB Output is correct
64 Correct 4967 ms 191100 KB Output is correct
65 Correct 429 ms 77264 KB Output is correct
66 Correct 528 ms 79212 KB Output is correct
67 Correct 422 ms 80704 KB Output is correct
68 Correct 427 ms 80620 KB Output is correct
69 Correct 888 ms 83052 KB Output is correct
70 Correct 35 ms 55276 KB Output is correct
71 Correct 895 ms 82796 KB Output is correct
72 Correct 539 ms 76652 KB Output is correct
73 Incorrect 731 ms 80748 KB Output isn't correct
74 Halted 0 ms 0 KB -