Submission #789712

# Submission time Handle Problem Language Result Execution time Memory
789712 2023-07-21T20:06:48 Z someone Two Dishes (JOI19_dishes) C++14
65 / 100
833 ms 234472 KB
#include <bits/stdc++.h>
#define int long long
using namespace std;

const int M = 1 << 18, N = 2 * M, INF = 1e18 + 42;

int n, m, maxi[N], tag[N], sum[N];
vector<int> a[2], s[2], p[2], pos[2];

void add(int i, int pt) {
    i = max(i, 0ll);
    i += M;
    while(i) {
        sum[i] += pt;
        i >>= 1;
    }
}

int getSum(int i) {
    if(i == -1) return 0;
    i += M;
    int ans = sum[i];
    while(i) {
        if(i & 1) ans += sum[i-1];
        i >>= 1;
    }
    return ans;
}

void applyOp(int i, int add) {
    tag[i] += add;
    maxi[i] += add;
}

void propage(int i) {
    applyOp(i*2, tag[i]);
    applyOp(i*2+1, tag[i]);
    tag[i] = 0;
}

int update(int i, int deb, int fin, int l, int r, int add) {
    if(r <= deb || fin <= l)
        return 0;
    if(l <= deb && fin <= r) {
        applyOp(i, add);
        return maxi[i];
    }
    propage(i);
    int mid = ((deb + fin) >> 1);
    int ans = max(update(i*2, deb, mid, l, r, add),
                  update(i*2+1, mid, fin, l, r, add));
    maxi[i] = max(maxi[i*2], maxi[i*2+1]);
    return ans;
}

int solve() {
    for(int i = 0; i < N; i++)
        maxi[i] = tag[i] = sum[i] = 0;

    vector<int> ver[M];
    for(int i = 1; i <= m; i++)
        if(pos[1][i] >= 0)
            ver[pos[1][i]].push_back(i);

    int ans = 0;
    for(int i = n; i >= 0; i--) {
        for(int j : ver[i]) {
            add(j, p[1][j]);
            update(1, 0, M, j, M, p[1][j]);
        }
        int dp = update(1, 0, M, pos[0][i], M, 0);
        ans = max(ans, dp - getSum(pos[0][i]));
        int val = update(1, 0, M, pos[0][i], pos[0][i]+1, 0);
        update(1, 0, M, pos[0][i], pos[0][i]+1, -val);
        update(1, 0, M, pos[0][i], pos[0][i]+1, dp);
        update(1, 0, M, 0, pos[0][i]+1, p[0][i]);
    }
    return ans;
}

signed main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);

    cin >> n >> m;
    int sz[] = {n+1, m+1};
    for(int i = 0; i < 2; i++) {
        a[i].resize(sz[i]);
        s[i].resize(sz[i]);
        p[i].resize(sz[i]);
        pos[i].resize(sz[i]);
    }

    for(int i = 1; i <= n; i++)
        cin >> a[0][i] >> s[0][i] >> p[0][i];
    for(int i = 1; i <= m; i++)
        cin >> a[1][i] >> s[1][i] >> p[1][i];
    for(int i = 1; i <= n; i++)
        a[0][i] += a[0][i-1];
    for(int i = 1; i <= m; i++)
        a[1][i] += a[1][i-1];

    for(int i = 0; i <= n; i++)
        pos[0][i] = (int)(upper_bound(a[1].begin(), a[1].end(), s[0][i] - a[0][i]) - a[1].begin())-1;
    for(int i = 0; i <= m; i++)
        pos[1][i] = (int)(upper_bound(a[0].begin(), a[0].end(), s[1][i] - a[1][i]) - a[0].begin())-1;


    int ans = solve();
    swap(n, m);
    swap(a[0], a[1]);
    swap(s[0], s[1]);
    swap(p[0], p[1]);
    swap(pos[0], pos[1]);
    cout << max(ans, solve()) << '\n';
}
# Verdict Execution time Memory Grader output
1 Correct 538 ms 38928 KB Output is correct
2 Correct 573 ms 45448 KB Output is correct
3 Correct 519 ms 43088 KB Output is correct
4 Correct 410 ms 43672 KB Output is correct
5 Correct 9 ms 18704 KB Output is correct
6 Correct 550 ms 39996 KB Output is correct
7 Correct 259 ms 33480 KB Output is correct
8 Correct 290 ms 34216 KB Output is correct
9 Correct 517 ms 49312 KB Output is correct
10 Correct 561 ms 44960 KB Output is correct
11 Correct 485 ms 42712 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 8 ms 18760 KB Output is correct
2 Correct 8 ms 18772 KB Output is correct
3 Correct 9 ms 18760 KB Output is correct
4 Correct 8 ms 18772 KB Output is correct
5 Correct 9 ms 18772 KB Output is correct
6 Correct 10 ms 18772 KB Output is correct
7 Correct 9 ms 18660 KB Output is correct
8 Correct 9 ms 18772 KB Output is correct
9 Correct 9 ms 18772 KB Output is correct
10 Correct 8 ms 18772 KB Output is correct
11 Correct 8 ms 18772 KB Output is correct
12 Correct 8 ms 18756 KB Output is correct
13 Correct 8 ms 18760 KB Output is correct
14 Correct 8 ms 18772 KB Output is correct
15 Correct 8 ms 18760 KB Output is correct
16 Correct 9 ms 18772 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 8 ms 18760 KB Output is correct
2 Correct 8 ms 18772 KB Output is correct
3 Correct 9 ms 18760 KB Output is correct
4 Correct 8 ms 18772 KB Output is correct
5 Correct 9 ms 18772 KB Output is correct
6 Correct 10 ms 18772 KB Output is correct
7 Correct 9 ms 18660 KB Output is correct
8 Correct 9 ms 18772 KB Output is correct
9 Correct 9 ms 18772 KB Output is correct
10 Correct 8 ms 18772 KB Output is correct
11 Correct 8 ms 18772 KB Output is correct
12 Correct 8 ms 18756 KB Output is correct
13 Correct 8 ms 18760 KB Output is correct
14 Correct 8 ms 18772 KB Output is correct
15 Correct 8 ms 18760 KB Output is correct
16 Correct 9 ms 18772 KB Output is correct
17 Correct 12 ms 19024 KB Output is correct
18 Correct 12 ms 19036 KB Output is correct
19 Correct 14 ms 19028 KB Output is correct
20 Correct 11 ms 19028 KB Output is correct
21 Correct 14 ms 19004 KB Output is correct
22 Correct 14 ms 18992 KB Output is correct
23 Correct 14 ms 18900 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 8 ms 18760 KB Output is correct
2 Correct 8 ms 18772 KB Output is correct
3 Correct 9 ms 18760 KB Output is correct
4 Correct 8 ms 18772 KB Output is correct
5 Correct 9 ms 18772 KB Output is correct
6 Correct 10 ms 18772 KB Output is correct
7 Correct 9 ms 18660 KB Output is correct
8 Correct 9 ms 18772 KB Output is correct
9 Correct 9 ms 18772 KB Output is correct
10 Correct 8 ms 18772 KB Output is correct
11 Correct 8 ms 18772 KB Output is correct
12 Correct 8 ms 18756 KB Output is correct
13 Correct 8 ms 18760 KB Output is correct
14 Correct 8 ms 18772 KB Output is correct
15 Correct 8 ms 18760 KB Output is correct
16 Correct 9 ms 18772 KB Output is correct
17 Correct 12 ms 19024 KB Output is correct
18 Correct 12 ms 19036 KB Output is correct
19 Correct 14 ms 19028 KB Output is correct
20 Correct 11 ms 19028 KB Output is correct
21 Correct 14 ms 19004 KB Output is correct
22 Correct 14 ms 18992 KB Output is correct
23 Correct 14 ms 18900 KB Output is correct
24 Correct 409 ms 44208 KB Output is correct
25 Correct 407 ms 44076 KB Output is correct
26 Correct 443 ms 48260 KB Output is correct
27 Correct 451 ms 48312 KB Output is correct
28 Correct 529 ms 45348 KB Output is correct
29 Correct 500 ms 46316 KB Output is correct
30 Correct 785 ms 46188 KB Output is correct
31 Correct 281 ms 31956 KB Output is correct
32 Correct 268 ms 32168 KB Output is correct
33 Correct 442 ms 44072 KB Output is correct
34 Correct 671 ms 45444 KB Output is correct
35 Correct 768 ms 39884 KB Output is correct
36 Correct 755 ms 39796 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 8 ms 18760 KB Output is correct
2 Correct 8 ms 18772 KB Output is correct
3 Correct 9 ms 18760 KB Output is correct
4 Correct 8 ms 18772 KB Output is correct
5 Correct 9 ms 18772 KB Output is correct
6 Correct 10 ms 18772 KB Output is correct
7 Correct 9 ms 18660 KB Output is correct
8 Correct 9 ms 18772 KB Output is correct
9 Correct 9 ms 18772 KB Output is correct
10 Correct 8 ms 18772 KB Output is correct
11 Correct 8 ms 18772 KB Output is correct
12 Correct 8 ms 18756 KB Output is correct
13 Correct 8 ms 18760 KB Output is correct
14 Correct 8 ms 18772 KB Output is correct
15 Correct 8 ms 18760 KB Output is correct
16 Correct 9 ms 18772 KB Output is correct
17 Correct 12 ms 19024 KB Output is correct
18 Correct 12 ms 19036 KB Output is correct
19 Correct 14 ms 19028 KB Output is correct
20 Correct 11 ms 19028 KB Output is correct
21 Correct 14 ms 19004 KB Output is correct
22 Correct 14 ms 18992 KB Output is correct
23 Correct 14 ms 18900 KB Output is correct
24 Correct 409 ms 44208 KB Output is correct
25 Correct 407 ms 44076 KB Output is correct
26 Correct 443 ms 48260 KB Output is correct
27 Correct 451 ms 48312 KB Output is correct
28 Correct 529 ms 45348 KB Output is correct
29 Correct 500 ms 46316 KB Output is correct
30 Correct 785 ms 46188 KB Output is correct
31 Correct 281 ms 31956 KB Output is correct
32 Correct 268 ms 32168 KB Output is correct
33 Correct 442 ms 44072 KB Output is correct
34 Correct 671 ms 45444 KB Output is correct
35 Correct 768 ms 39884 KB Output is correct
36 Correct 755 ms 39796 KB Output is correct
37 Correct 460 ms 51360 KB Output is correct
38 Correct 457 ms 51252 KB Output is correct
39 Correct 586 ms 48604 KB Output is correct
40 Correct 576 ms 48576 KB Output is correct
41 Correct 8 ms 18772 KB Output is correct
42 Correct 833 ms 49220 KB Output is correct
43 Correct 475 ms 46944 KB Output is correct
44 Correct 756 ms 48224 KB Output is correct
45 Correct 826 ms 42876 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 8 ms 18760 KB Output is correct
2 Correct 8 ms 18772 KB Output is correct
3 Correct 9 ms 18760 KB Output is correct
4 Correct 8 ms 18772 KB Output is correct
5 Correct 9 ms 18772 KB Output is correct
6 Correct 10 ms 18772 KB Output is correct
7 Correct 9 ms 18660 KB Output is correct
8 Correct 9 ms 18772 KB Output is correct
9 Correct 9 ms 18772 KB Output is correct
10 Correct 8 ms 18772 KB Output is correct
11 Correct 8 ms 18772 KB Output is correct
12 Correct 8 ms 18756 KB Output is correct
13 Correct 8 ms 18760 KB Output is correct
14 Correct 8 ms 18772 KB Output is correct
15 Correct 8 ms 18760 KB Output is correct
16 Correct 9 ms 18772 KB Output is correct
17 Correct 12 ms 19024 KB Output is correct
18 Correct 12 ms 19036 KB Output is correct
19 Correct 14 ms 19028 KB Output is correct
20 Correct 11 ms 19028 KB Output is correct
21 Correct 14 ms 19004 KB Output is correct
22 Correct 14 ms 18992 KB Output is correct
23 Correct 14 ms 18900 KB Output is correct
24 Correct 409 ms 44208 KB Output is correct
25 Correct 407 ms 44076 KB Output is correct
26 Correct 443 ms 48260 KB Output is correct
27 Correct 451 ms 48312 KB Output is correct
28 Correct 529 ms 45348 KB Output is correct
29 Correct 500 ms 46316 KB Output is correct
30 Correct 785 ms 46188 KB Output is correct
31 Correct 281 ms 31956 KB Output is correct
32 Correct 268 ms 32168 KB Output is correct
33 Correct 442 ms 44072 KB Output is correct
34 Correct 671 ms 45444 KB Output is correct
35 Correct 768 ms 39884 KB Output is correct
36 Correct 755 ms 39796 KB Output is correct
37 Correct 460 ms 51360 KB Output is correct
38 Correct 457 ms 51252 KB Output is correct
39 Correct 586 ms 48604 KB Output is correct
40 Correct 576 ms 48576 KB Output is correct
41 Correct 8 ms 18772 KB Output is correct
42 Correct 833 ms 49220 KB Output is correct
43 Correct 475 ms 46944 KB Output is correct
44 Correct 756 ms 48224 KB Output is correct
45 Correct 826 ms 42876 KB Output is correct
46 Runtime error 723 ms 234472 KB Execution killed with signal 11
47 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 538 ms 38928 KB Output is correct
2 Correct 573 ms 45448 KB Output is correct
3 Correct 519 ms 43088 KB Output is correct
4 Correct 410 ms 43672 KB Output is correct
5 Correct 9 ms 18704 KB Output is correct
6 Correct 550 ms 39996 KB Output is correct
7 Correct 259 ms 33480 KB Output is correct
8 Correct 290 ms 34216 KB Output is correct
9 Correct 517 ms 49312 KB Output is correct
10 Correct 561 ms 44960 KB Output is correct
11 Correct 485 ms 42712 KB Output is correct
12 Correct 8 ms 18760 KB Output is correct
13 Correct 8 ms 18772 KB Output is correct
14 Correct 9 ms 18760 KB Output is correct
15 Correct 8 ms 18772 KB Output is correct
16 Correct 9 ms 18772 KB Output is correct
17 Correct 10 ms 18772 KB Output is correct
18 Correct 9 ms 18660 KB Output is correct
19 Correct 9 ms 18772 KB Output is correct
20 Correct 9 ms 18772 KB Output is correct
21 Correct 8 ms 18772 KB Output is correct
22 Correct 8 ms 18772 KB Output is correct
23 Correct 8 ms 18756 KB Output is correct
24 Correct 8 ms 18760 KB Output is correct
25 Correct 8 ms 18772 KB Output is correct
26 Correct 8 ms 18760 KB Output is correct
27 Correct 9 ms 18772 KB Output is correct
28 Correct 12 ms 19024 KB Output is correct
29 Correct 12 ms 19036 KB Output is correct
30 Correct 14 ms 19028 KB Output is correct
31 Correct 11 ms 19028 KB Output is correct
32 Correct 14 ms 19004 KB Output is correct
33 Correct 14 ms 18992 KB Output is correct
34 Correct 14 ms 18900 KB Output is correct
35 Correct 409 ms 44208 KB Output is correct
36 Correct 407 ms 44076 KB Output is correct
37 Correct 443 ms 48260 KB Output is correct
38 Correct 451 ms 48312 KB Output is correct
39 Correct 529 ms 45348 KB Output is correct
40 Correct 500 ms 46316 KB Output is correct
41 Correct 785 ms 46188 KB Output is correct
42 Correct 281 ms 31956 KB Output is correct
43 Correct 268 ms 32168 KB Output is correct
44 Correct 442 ms 44072 KB Output is correct
45 Correct 671 ms 45444 KB Output is correct
46 Correct 768 ms 39884 KB Output is correct
47 Correct 755 ms 39796 KB Output is correct
48 Correct 460 ms 51360 KB Output is correct
49 Correct 457 ms 51252 KB Output is correct
50 Correct 586 ms 48604 KB Output is correct
51 Correct 576 ms 48576 KB Output is correct
52 Correct 8 ms 18772 KB Output is correct
53 Correct 833 ms 49220 KB Output is correct
54 Correct 475 ms 46944 KB Output is correct
55 Correct 756 ms 48224 KB Output is correct
56 Correct 826 ms 42876 KB Output is correct
57 Incorrect 483 ms 51744 KB Output isn't correct
58 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 538 ms 38928 KB Output is correct
2 Correct 573 ms 45448 KB Output is correct
3 Correct 519 ms 43088 KB Output is correct
4 Correct 410 ms 43672 KB Output is correct
5 Correct 9 ms 18704 KB Output is correct
6 Correct 550 ms 39996 KB Output is correct
7 Correct 259 ms 33480 KB Output is correct
8 Correct 290 ms 34216 KB Output is correct
9 Correct 517 ms 49312 KB Output is correct
10 Correct 561 ms 44960 KB Output is correct
11 Correct 485 ms 42712 KB Output is correct
12 Correct 8 ms 18760 KB Output is correct
13 Correct 8 ms 18772 KB Output is correct
14 Correct 9 ms 18760 KB Output is correct
15 Correct 8 ms 18772 KB Output is correct
16 Correct 9 ms 18772 KB Output is correct
17 Correct 10 ms 18772 KB Output is correct
18 Correct 9 ms 18660 KB Output is correct
19 Correct 9 ms 18772 KB Output is correct
20 Correct 9 ms 18772 KB Output is correct
21 Correct 8 ms 18772 KB Output is correct
22 Correct 8 ms 18772 KB Output is correct
23 Correct 8 ms 18756 KB Output is correct
24 Correct 8 ms 18760 KB Output is correct
25 Correct 8 ms 18772 KB Output is correct
26 Correct 8 ms 18760 KB Output is correct
27 Correct 9 ms 18772 KB Output is correct
28 Correct 12 ms 19024 KB Output is correct
29 Correct 12 ms 19036 KB Output is correct
30 Correct 14 ms 19028 KB Output is correct
31 Correct 11 ms 19028 KB Output is correct
32 Correct 14 ms 19004 KB Output is correct
33 Correct 14 ms 18992 KB Output is correct
34 Correct 14 ms 18900 KB Output is correct
35 Correct 409 ms 44208 KB Output is correct
36 Correct 407 ms 44076 KB Output is correct
37 Correct 443 ms 48260 KB Output is correct
38 Correct 451 ms 48312 KB Output is correct
39 Correct 529 ms 45348 KB Output is correct
40 Correct 500 ms 46316 KB Output is correct
41 Correct 785 ms 46188 KB Output is correct
42 Correct 281 ms 31956 KB Output is correct
43 Correct 268 ms 32168 KB Output is correct
44 Correct 442 ms 44072 KB Output is correct
45 Correct 671 ms 45444 KB Output is correct
46 Correct 768 ms 39884 KB Output is correct
47 Correct 755 ms 39796 KB Output is correct
48 Correct 460 ms 51360 KB Output is correct
49 Correct 457 ms 51252 KB Output is correct
50 Correct 586 ms 48604 KB Output is correct
51 Correct 576 ms 48576 KB Output is correct
52 Correct 8 ms 18772 KB Output is correct
53 Correct 833 ms 49220 KB Output is correct
54 Correct 475 ms 46944 KB Output is correct
55 Correct 756 ms 48224 KB Output is correct
56 Correct 826 ms 42876 KB Output is correct
57 Runtime error 723 ms 234472 KB Execution killed with signal 11
58 Halted 0 ms 0 KB -