답안 #510867

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
510867 2022-01-15T03:31:43 Z couplefire Two Dishes (JOI19_dishes) C++17
0 / 100
369 ms 73028 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(i-1>=0 && upa[i]+1<=m) stuff[i-1].push_back({upa[i]+1, -pa[i]});
        else ans -= pa[i];
    for(int i = 1; i<=m; ++i)
        if(upb[i]>=0 && i<=m) 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 : 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';
}
# 결과 실행 시간 메모리 Grader output
1 Correct 302 ms 73028 KB Output is correct
2 Incorrect 369 ms 63236 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 13 ms 23868 KB Output is correct
2 Correct 14 ms 23756 KB Output is correct
3 Incorrect 14 ms 23808 KB Output isn't correct
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 13 ms 23868 KB Output is correct
2 Correct 14 ms 23756 KB Output is correct
3 Incorrect 14 ms 23808 KB Output isn't correct
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 13 ms 23868 KB Output is correct
2 Correct 14 ms 23756 KB Output is correct
3 Incorrect 14 ms 23808 KB Output isn't correct
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 13 ms 23868 KB Output is correct
2 Correct 14 ms 23756 KB Output is correct
3 Incorrect 14 ms 23808 KB Output isn't correct
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 13 ms 23868 KB Output is correct
2 Correct 14 ms 23756 KB Output is correct
3 Incorrect 14 ms 23808 KB Output isn't correct
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 302 ms 73028 KB Output is correct
2 Incorrect 369 ms 63236 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 302 ms 73028 KB Output is correct
2 Incorrect 369 ms 63236 KB Output isn't correct
3 Halted 0 ms 0 KB -