Submission #510883

# Submission time Handle Problem Language Result Execution time Memory
510883 2022-01-15T03:38:16 Z couplefire Two Dishes (JOI19_dishes) C++17
0 / 100
348 ms 59728 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)
        stuff[i-1].push_back({upa[i]+1, -pa[i]});
    for(int i = 1; i<=m; ++i)
        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 Incorrect 348 ms 59728 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 13 ms 23756 KB Output is correct
2 Incorrect 15 ms 23848 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 13 ms 23756 KB Output is correct
2 Incorrect 15 ms 23848 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 13 ms 23756 KB Output is correct
2 Incorrect 15 ms 23848 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 13 ms 23756 KB Output is correct
2 Incorrect 15 ms 23848 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 13 ms 23756 KB Output is correct
2 Incorrect 15 ms 23848 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 348 ms 59728 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 348 ms 59728 KB Output isn't correct
2 Halted 0 ms 0 KB -