Submission #510962

# Submission time Handle Problem Language Result Execution time Memory
510962 2022-01-15T03:54:49 Z couplefire Two Dishes (JOI19_dishes) C++17
5 / 100
372 ms 59432 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(){
    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){
        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]});
            }
        } if(i==0) continue;
        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(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 372 ms 59432 KB Output is correct
2 Correct 338 ms 49340 KB Output is correct
3 Correct 329 ms 53620 KB Output is correct
4 Correct 328 ms 52884 KB Output is correct
5 Correct 17 ms 23756 KB Output is correct
6 Correct 310 ms 48840 KB Output is correct
7 Correct 171 ms 45592 KB Output is correct
8 Correct 101 ms 30084 KB Output is correct
9 Correct 267 ms 53592 KB Output is correct
10 Correct 276 ms 47340 KB Output is correct
11 Correct 240 ms 53484 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 16 ms 23820 KB Output is correct
2 Correct 15 ms 23764 KB Output is correct
3 Correct 15 ms 23752 KB Output is correct
4 Correct 17 ms 23760 KB Output is correct
5 Correct 19 ms 23868 KB Output is correct
6 Correct 18 ms 23756 KB Output is correct
7 Incorrect 17 ms 23756 KB Output isn't correct
8 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 16 ms 23820 KB Output is correct
2 Correct 15 ms 23764 KB Output is correct
3 Correct 15 ms 23752 KB Output is correct
4 Correct 17 ms 23760 KB Output is correct
5 Correct 19 ms 23868 KB Output is correct
6 Correct 18 ms 23756 KB Output is correct
7 Incorrect 17 ms 23756 KB Output isn't correct
8 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 16 ms 23820 KB Output is correct
2 Correct 15 ms 23764 KB Output is correct
3 Correct 15 ms 23752 KB Output is correct
4 Correct 17 ms 23760 KB Output is correct
5 Correct 19 ms 23868 KB Output is correct
6 Correct 18 ms 23756 KB Output is correct
7 Incorrect 17 ms 23756 KB Output isn't correct
8 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 16 ms 23820 KB Output is correct
2 Correct 15 ms 23764 KB Output is correct
3 Correct 15 ms 23752 KB Output is correct
4 Correct 17 ms 23760 KB Output is correct
5 Correct 19 ms 23868 KB Output is correct
6 Correct 18 ms 23756 KB Output is correct
7 Incorrect 17 ms 23756 KB Output isn't correct
8 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 16 ms 23820 KB Output is correct
2 Correct 15 ms 23764 KB Output is correct
3 Correct 15 ms 23752 KB Output is correct
4 Correct 17 ms 23760 KB Output is correct
5 Correct 19 ms 23868 KB Output is correct
6 Correct 18 ms 23756 KB Output is correct
7 Incorrect 17 ms 23756 KB Output isn't correct
8 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 372 ms 59432 KB Output is correct
2 Correct 338 ms 49340 KB Output is correct
3 Correct 329 ms 53620 KB Output is correct
4 Correct 328 ms 52884 KB Output is correct
5 Correct 17 ms 23756 KB Output is correct
6 Correct 310 ms 48840 KB Output is correct
7 Correct 171 ms 45592 KB Output is correct
8 Correct 101 ms 30084 KB Output is correct
9 Correct 267 ms 53592 KB Output is correct
10 Correct 276 ms 47340 KB Output is correct
11 Correct 240 ms 53484 KB Output is correct
12 Correct 16 ms 23820 KB Output is correct
13 Correct 15 ms 23764 KB Output is correct
14 Correct 15 ms 23752 KB Output is correct
15 Correct 17 ms 23760 KB Output is correct
16 Correct 19 ms 23868 KB Output is correct
17 Correct 18 ms 23756 KB Output is correct
18 Incorrect 17 ms 23756 KB Output isn't correct
19 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 372 ms 59432 KB Output is correct
2 Correct 338 ms 49340 KB Output is correct
3 Correct 329 ms 53620 KB Output is correct
4 Correct 328 ms 52884 KB Output is correct
5 Correct 17 ms 23756 KB Output is correct
6 Correct 310 ms 48840 KB Output is correct
7 Correct 171 ms 45592 KB Output is correct
8 Correct 101 ms 30084 KB Output is correct
9 Correct 267 ms 53592 KB Output is correct
10 Correct 276 ms 47340 KB Output is correct
11 Correct 240 ms 53484 KB Output is correct
12 Correct 16 ms 23820 KB Output is correct
13 Correct 15 ms 23764 KB Output is correct
14 Correct 15 ms 23752 KB Output is correct
15 Correct 17 ms 23760 KB Output is correct
16 Correct 19 ms 23868 KB Output is correct
17 Correct 18 ms 23756 KB Output is correct
18 Incorrect 17 ms 23756 KB Output isn't correct
19 Halted 0 ms 0 KB -