Submission #510889

# Submission time Handle Problem Language Result Execution time Memory
510889 2022-01-15T03:40:20 Z couplefire Two Dishes (JOI19_dishes) C++17
74 / 100
4233 ms 265912 KB
#include <bits/stdc++.h>
using namespace std;
#define ll long long

const int N = 1000005;

int n, m; ll upa[N], upb[N], val[N];
ll sa[N], sb[N], bda[N], bdb[N], pa[N], pb[N];
vector<pair<ll, ll>> stuff[N];
ll ans = 0; set<pair<ll, ll>> st;

int main(){
    // freopen("a.in", "r", stdin);
    cin.tie(0)->sync_with_stdio(0);
    cin >> n >> m;
    for(int i = 1; i<=n; ++i)
        cin >> sa[i] >> bda[i] >> pa[i];
    for(int i = 1; i<=m; ++i)
        cin >> sb[i] >> bdb[i] >> pb[i];
    for(int i = 1; i<=n; ++i)
        sa[i] += sa[i-1];
    for(int i = 1; i<=m; ++i)
        sb[i] += sb[i-1];
    for(int i = 1; i<=n; ++i)
        upa[i] = upper_bound(sb, sb+m+1, bda[i]-sa[i])-sb-1;
    for(int i = 1; i<=m; ++i)
        upb[i] = upper_bound(sa, sa+n+1, bdb[i]-sb[i])-sa-1;
    for(int i = 1; i<=n; ++i)
        if(upa[i]+1<=m) stuff[i-1].push_back({upa[i]+1, -pa[i]});
    for(int i = 1; i<=m; ++i)
        if(upb[i]>=0) stuff[upb[i]].push_back({i, pb[i]});
    for(int i = 0; i<=n; ++i)
        sort(stuff[i].begin(), stuff[i].end());
    for(int i = 0; i<=n; ++i){
        vector<int> pos;
        for(auto [y, p] : stuff[i]){
            if(y==0ll) ans += p;
            else{
                auto it = st.find({y, val[y]});
                if(it!=st.end()) st.erase(it);
                if((val[y] += p)<0) pos.push_back(y);
                if(val[y]!=0) st.insert({y, val[y]});
            }
        }
        // for(auto [y, p] : st)
        //     cout << '[' << y << ", " << p << ']' << ' ';
        // cout << '\n';
        for(auto y : pos) while(val[y]<0){
            auto it = st.upper_bound({y, val[y]});
            if(it==st.end()){
                st.erase({y, val[y]});
                val[y] = 0; continue;
            }
            int yy = it->first; st.erase(it);
            st.erase({y, val[y]});
            ll d = min(-val[y], val[yy]);
            val[y] += d; val[yy] -= d;
            if(val[y]!=0) st.insert({y, val[y]});
            if(val[yy]!=0) st.insert({yy, val[yy]});
        }
        // for(auto [y, p] : st)
        //     cout << '[' << y << ", " << p << ']' << ' ';
        // cout << '\n';
        // cout << '\n';
    }
    for(int i = 1; i<=n; ++i)
        ans += pa[i];
    for(auto [y, p] : st)
        ans += p;
    cout << ans << '\n';
}
# Verdict Execution time Memory Grader output
1 Correct 384 ms 59452 KB Output is correct
2 Correct 343 ms 49460 KB Output is correct
3 Correct 381 ms 66976 KB Output is correct
4 Correct 439 ms 66628 KB Output is correct
5 Correct 19 ms 23832 KB Output is correct
6 Correct 400 ms 62304 KB Output is correct
7 Correct 231 ms 52392 KB Output is correct
8 Correct 113 ms 37108 KB Output is correct
9 Correct 371 ms 67996 KB Output is correct
10 Correct 282 ms 54780 KB Output is correct
11 Correct 288 ms 61296 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 18 ms 23756 KB Output is correct
2 Correct 13 ms 23736 KB Output is correct
3 Correct 18 ms 23800 KB Output is correct
4 Correct 14 ms 23792 KB Output is correct
5 Correct 17 ms 23804 KB Output is correct
6 Correct 17 ms 23800 KB Output is correct
7 Correct 14 ms 23808 KB Output is correct
8 Correct 16 ms 23756 KB Output is correct
9 Correct 13 ms 23808 KB Output is correct
10 Correct 28 ms 23756 KB Output is correct
11 Correct 17 ms 23792 KB Output is correct
12 Correct 18 ms 23816 KB Output is correct
13 Correct 15 ms 23756 KB Output is correct
14 Correct 18 ms 23776 KB Output is correct
15 Correct 19 ms 23804 KB Output is correct
16 Correct 18 ms 23868 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 18 ms 23756 KB Output is correct
2 Correct 13 ms 23736 KB Output is correct
3 Correct 18 ms 23800 KB Output is correct
4 Correct 14 ms 23792 KB Output is correct
5 Correct 17 ms 23804 KB Output is correct
6 Correct 17 ms 23800 KB Output is correct
7 Correct 14 ms 23808 KB Output is correct
8 Correct 16 ms 23756 KB Output is correct
9 Correct 13 ms 23808 KB Output is correct
10 Correct 28 ms 23756 KB Output is correct
11 Correct 17 ms 23792 KB Output is correct
12 Correct 18 ms 23816 KB Output is correct
13 Correct 15 ms 23756 KB Output is correct
14 Correct 18 ms 23776 KB Output is correct
15 Correct 19 ms 23804 KB Output is correct
16 Correct 18 ms 23868 KB Output is correct
17 Correct 21 ms 24228 KB Output is correct
18 Correct 16 ms 24204 KB Output is correct
19 Correct 16 ms 24200 KB Output is correct
20 Correct 21 ms 24168 KB Output is correct
21 Correct 19 ms 24200 KB Output is correct
22 Correct 16 ms 24064 KB Output is correct
23 Correct 21 ms 24120 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 18 ms 23756 KB Output is correct
2 Correct 13 ms 23736 KB Output is correct
3 Correct 18 ms 23800 KB Output is correct
4 Correct 14 ms 23792 KB Output is correct
5 Correct 17 ms 23804 KB Output is correct
6 Correct 17 ms 23800 KB Output is correct
7 Correct 14 ms 23808 KB Output is correct
8 Correct 16 ms 23756 KB Output is correct
9 Correct 13 ms 23808 KB Output is correct
10 Correct 28 ms 23756 KB Output is correct
11 Correct 17 ms 23792 KB Output is correct
12 Correct 18 ms 23816 KB Output is correct
13 Correct 15 ms 23756 KB Output is correct
14 Correct 18 ms 23776 KB Output is correct
15 Correct 19 ms 23804 KB Output is correct
16 Correct 18 ms 23868 KB Output is correct
17 Correct 21 ms 24228 KB Output is correct
18 Correct 16 ms 24204 KB Output is correct
19 Correct 16 ms 24200 KB Output is correct
20 Correct 21 ms 24168 KB Output is correct
21 Correct 19 ms 24200 KB Output is correct
22 Correct 16 ms 24064 KB Output is correct
23 Correct 21 ms 24120 KB Output is correct
24 Correct 327 ms 62584 KB Output is correct
25 Correct 292 ms 67216 KB Output is correct
26 Correct 254 ms 62676 KB Output is correct
27 Correct 328 ms 68884 KB Output is correct
28 Correct 341 ms 62176 KB Output is correct
29 Correct 280 ms 64912 KB Output is correct
30 Correct 597 ms 60348 KB Output is correct
31 Correct 170 ms 52528 KB Output is correct
32 Correct 124 ms 38488 KB Output is correct
33 Correct 406 ms 57636 KB Output is correct
34 Correct 460 ms 64540 KB Output is correct
35 Correct 471 ms 53884 KB Output is correct
36 Correct 458 ms 53912 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 18 ms 23756 KB Output is correct
2 Correct 13 ms 23736 KB Output is correct
3 Correct 18 ms 23800 KB Output is correct
4 Correct 14 ms 23792 KB Output is correct
5 Correct 17 ms 23804 KB Output is correct
6 Correct 17 ms 23800 KB Output is correct
7 Correct 14 ms 23808 KB Output is correct
8 Correct 16 ms 23756 KB Output is correct
9 Correct 13 ms 23808 KB Output is correct
10 Correct 28 ms 23756 KB Output is correct
11 Correct 17 ms 23792 KB Output is correct
12 Correct 18 ms 23816 KB Output is correct
13 Correct 15 ms 23756 KB Output is correct
14 Correct 18 ms 23776 KB Output is correct
15 Correct 19 ms 23804 KB Output is correct
16 Correct 18 ms 23868 KB Output is correct
17 Correct 21 ms 24228 KB Output is correct
18 Correct 16 ms 24204 KB Output is correct
19 Correct 16 ms 24200 KB Output is correct
20 Correct 21 ms 24168 KB Output is correct
21 Correct 19 ms 24200 KB Output is correct
22 Correct 16 ms 24064 KB Output is correct
23 Correct 21 ms 24120 KB Output is correct
24 Correct 327 ms 62584 KB Output is correct
25 Correct 292 ms 67216 KB Output is correct
26 Correct 254 ms 62676 KB Output is correct
27 Correct 328 ms 68884 KB Output is correct
28 Correct 341 ms 62176 KB Output is correct
29 Correct 280 ms 64912 KB Output is correct
30 Correct 597 ms 60348 KB Output is correct
31 Correct 170 ms 52528 KB Output is correct
32 Correct 124 ms 38488 KB Output is correct
33 Correct 406 ms 57636 KB Output is correct
34 Correct 460 ms 64540 KB Output is correct
35 Correct 471 ms 53884 KB Output is correct
36 Correct 458 ms 53912 KB Output is correct
37 Correct 358 ms 65704 KB Output is correct
38 Correct 371 ms 71932 KB Output is correct
39 Correct 455 ms 70860 KB Output is correct
40 Correct 368 ms 58396 KB Output is correct
41 Correct 16 ms 23824 KB Output is correct
42 Correct 714 ms 63356 KB Output is correct
43 Correct 429 ms 60584 KB Output is correct
44 Correct 504 ms 67352 KB Output is correct
45 Correct 722 ms 57036 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 18 ms 23756 KB Output is correct
2 Correct 13 ms 23736 KB Output is correct
3 Correct 18 ms 23800 KB Output is correct
4 Correct 14 ms 23792 KB Output is correct
5 Correct 17 ms 23804 KB Output is correct
6 Correct 17 ms 23800 KB Output is correct
7 Correct 14 ms 23808 KB Output is correct
8 Correct 16 ms 23756 KB Output is correct
9 Correct 13 ms 23808 KB Output is correct
10 Correct 28 ms 23756 KB Output is correct
11 Correct 17 ms 23792 KB Output is correct
12 Correct 18 ms 23816 KB Output is correct
13 Correct 15 ms 23756 KB Output is correct
14 Correct 18 ms 23776 KB Output is correct
15 Correct 19 ms 23804 KB Output is correct
16 Correct 18 ms 23868 KB Output is correct
17 Correct 21 ms 24228 KB Output is correct
18 Correct 16 ms 24204 KB Output is correct
19 Correct 16 ms 24200 KB Output is correct
20 Correct 21 ms 24168 KB Output is correct
21 Correct 19 ms 24200 KB Output is correct
22 Correct 16 ms 24064 KB Output is correct
23 Correct 21 ms 24120 KB Output is correct
24 Correct 327 ms 62584 KB Output is correct
25 Correct 292 ms 67216 KB Output is correct
26 Correct 254 ms 62676 KB Output is correct
27 Correct 328 ms 68884 KB Output is correct
28 Correct 341 ms 62176 KB Output is correct
29 Correct 280 ms 64912 KB Output is correct
30 Correct 597 ms 60348 KB Output is correct
31 Correct 170 ms 52528 KB Output is correct
32 Correct 124 ms 38488 KB Output is correct
33 Correct 406 ms 57636 KB Output is correct
34 Correct 460 ms 64540 KB Output is correct
35 Correct 471 ms 53884 KB Output is correct
36 Correct 458 ms 53912 KB Output is correct
37 Correct 358 ms 65704 KB Output is correct
38 Correct 371 ms 71932 KB Output is correct
39 Correct 455 ms 70860 KB Output is correct
40 Correct 368 ms 58396 KB Output is correct
41 Correct 16 ms 23824 KB Output is correct
42 Correct 714 ms 63356 KB Output is correct
43 Correct 429 ms 60584 KB Output is correct
44 Correct 504 ms 67352 KB Output is correct
45 Correct 722 ms 57036 KB Output is correct
46 Correct 1814 ms 234588 KB Output is correct
47 Correct 2076 ms 265912 KB Output is correct
48 Correct 2738 ms 260044 KB Output is correct
49 Correct 1548 ms 197612 KB Output is correct
50 Correct 4233 ms 222740 KB Output is correct
51 Correct 2542 ms 206356 KB Output is correct
52 Correct 3365 ms 231980 KB Output is correct
53 Correct 3628 ms 191560 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 384 ms 59452 KB Output is correct
2 Correct 343 ms 49460 KB Output is correct
3 Correct 381 ms 66976 KB Output is correct
4 Correct 439 ms 66628 KB Output is correct
5 Correct 19 ms 23832 KB Output is correct
6 Correct 400 ms 62304 KB Output is correct
7 Correct 231 ms 52392 KB Output is correct
8 Correct 113 ms 37108 KB Output is correct
9 Correct 371 ms 67996 KB Output is correct
10 Correct 282 ms 54780 KB Output is correct
11 Correct 288 ms 61296 KB Output is correct
12 Correct 18 ms 23756 KB Output is correct
13 Correct 13 ms 23736 KB Output is correct
14 Correct 18 ms 23800 KB Output is correct
15 Correct 14 ms 23792 KB Output is correct
16 Correct 17 ms 23804 KB Output is correct
17 Correct 17 ms 23800 KB Output is correct
18 Correct 14 ms 23808 KB Output is correct
19 Correct 16 ms 23756 KB Output is correct
20 Correct 13 ms 23808 KB Output is correct
21 Correct 28 ms 23756 KB Output is correct
22 Correct 17 ms 23792 KB Output is correct
23 Correct 18 ms 23816 KB Output is correct
24 Correct 15 ms 23756 KB Output is correct
25 Correct 18 ms 23776 KB Output is correct
26 Correct 19 ms 23804 KB Output is correct
27 Correct 18 ms 23868 KB Output is correct
28 Correct 21 ms 24228 KB Output is correct
29 Correct 16 ms 24204 KB Output is correct
30 Correct 16 ms 24200 KB Output is correct
31 Correct 21 ms 24168 KB Output is correct
32 Correct 19 ms 24200 KB Output is correct
33 Correct 16 ms 24064 KB Output is correct
34 Correct 21 ms 24120 KB Output is correct
35 Correct 327 ms 62584 KB Output is correct
36 Correct 292 ms 67216 KB Output is correct
37 Correct 254 ms 62676 KB Output is correct
38 Correct 328 ms 68884 KB Output is correct
39 Correct 341 ms 62176 KB Output is correct
40 Correct 280 ms 64912 KB Output is correct
41 Correct 597 ms 60348 KB Output is correct
42 Correct 170 ms 52528 KB Output is correct
43 Correct 124 ms 38488 KB Output is correct
44 Correct 406 ms 57636 KB Output is correct
45 Correct 460 ms 64540 KB Output is correct
46 Correct 471 ms 53884 KB Output is correct
47 Correct 458 ms 53912 KB Output is correct
48 Correct 358 ms 65704 KB Output is correct
49 Correct 371 ms 71932 KB Output is correct
50 Correct 455 ms 70860 KB Output is correct
51 Correct 368 ms 58396 KB Output is correct
52 Correct 16 ms 23824 KB Output is correct
53 Correct 714 ms 63356 KB Output is correct
54 Correct 429 ms 60584 KB Output is correct
55 Correct 504 ms 67352 KB Output is correct
56 Correct 722 ms 57036 KB Output is correct
57 Incorrect 387 ms 72804 KB Output isn't correct
58 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 384 ms 59452 KB Output is correct
2 Correct 343 ms 49460 KB Output is correct
3 Correct 381 ms 66976 KB Output is correct
4 Correct 439 ms 66628 KB Output is correct
5 Correct 19 ms 23832 KB Output is correct
6 Correct 400 ms 62304 KB Output is correct
7 Correct 231 ms 52392 KB Output is correct
8 Correct 113 ms 37108 KB Output is correct
9 Correct 371 ms 67996 KB Output is correct
10 Correct 282 ms 54780 KB Output is correct
11 Correct 288 ms 61296 KB Output is correct
12 Correct 18 ms 23756 KB Output is correct
13 Correct 13 ms 23736 KB Output is correct
14 Correct 18 ms 23800 KB Output is correct
15 Correct 14 ms 23792 KB Output is correct
16 Correct 17 ms 23804 KB Output is correct
17 Correct 17 ms 23800 KB Output is correct
18 Correct 14 ms 23808 KB Output is correct
19 Correct 16 ms 23756 KB Output is correct
20 Correct 13 ms 23808 KB Output is correct
21 Correct 28 ms 23756 KB Output is correct
22 Correct 17 ms 23792 KB Output is correct
23 Correct 18 ms 23816 KB Output is correct
24 Correct 15 ms 23756 KB Output is correct
25 Correct 18 ms 23776 KB Output is correct
26 Correct 19 ms 23804 KB Output is correct
27 Correct 18 ms 23868 KB Output is correct
28 Correct 21 ms 24228 KB Output is correct
29 Correct 16 ms 24204 KB Output is correct
30 Correct 16 ms 24200 KB Output is correct
31 Correct 21 ms 24168 KB Output is correct
32 Correct 19 ms 24200 KB Output is correct
33 Correct 16 ms 24064 KB Output is correct
34 Correct 21 ms 24120 KB Output is correct
35 Correct 327 ms 62584 KB Output is correct
36 Correct 292 ms 67216 KB Output is correct
37 Correct 254 ms 62676 KB Output is correct
38 Correct 328 ms 68884 KB Output is correct
39 Correct 341 ms 62176 KB Output is correct
40 Correct 280 ms 64912 KB Output is correct
41 Correct 597 ms 60348 KB Output is correct
42 Correct 170 ms 52528 KB Output is correct
43 Correct 124 ms 38488 KB Output is correct
44 Correct 406 ms 57636 KB Output is correct
45 Correct 460 ms 64540 KB Output is correct
46 Correct 471 ms 53884 KB Output is correct
47 Correct 458 ms 53912 KB Output is correct
48 Correct 358 ms 65704 KB Output is correct
49 Correct 371 ms 71932 KB Output is correct
50 Correct 455 ms 70860 KB Output is correct
51 Correct 368 ms 58396 KB Output is correct
52 Correct 16 ms 23824 KB Output is correct
53 Correct 714 ms 63356 KB Output is correct
54 Correct 429 ms 60584 KB Output is correct
55 Correct 504 ms 67352 KB Output is correct
56 Correct 722 ms 57036 KB Output is correct
57 Correct 1814 ms 234588 KB Output is correct
58 Correct 2076 ms 265912 KB Output is correct
59 Correct 2738 ms 260044 KB Output is correct
60 Correct 1548 ms 197612 KB Output is correct
61 Correct 4233 ms 222740 KB Output is correct
62 Correct 2542 ms 206356 KB Output is correct
63 Correct 3365 ms 231980 KB Output is correct
64 Correct 3628 ms 191560 KB Output is correct
65 Incorrect 387 ms 72804 KB Output isn't correct
66 Halted 0 ms 0 KB -