Submission #890720

# Submission time Handle Problem Language Result Execution time Memory
890720 2023-12-21T19:33:41 Z Ahmed57 Ants and Sugar (JOI22_sugar) C++17
0 / 100
1 ms 504 KB
#include <bits/stdc++.h>

using namespace std;
#define int long long

signed main(){
    ios_base::sync_with_stdio(0);cin.tie(0);
    //freopen("input.txt","r",stdin);
    //freopen("outout.txt","w",stdout);
    int n,m;
    cin>>n>>m;
    multiset<array<int,3>> s;
    for(int i = 1;i<=n;i++){
        int t,x,a;
        cin>>t>>x>>a;
        s.insert({x,t,a});multiset<pair<int,int>> sugar,ants;
        long long all = 0;
        for(auto i:s){
            int rem = i[2];
            if(i[1]==2){
                while(!ants.empty()&&abs((-(*ants.begin()).first)-i[2])<=m&&rem){
                    int pos = (*ants.begin()).first;
                    int sec = (*ants.begin()).second;
                    int e = min(sec,rem);
                    rem-=e;sec-=e;
                    all+=e;
                    if(sec!=0){
                        ants.insert({pos,sec});
                    }
                }
                if(rem)sugar.insert({-i[0],rem});
            }else{
                while(!sugar.empty()&&abs((-(*sugar.begin()).first)-i[2])<=m&&rem){
                    int pos = (*sugar.begin()).first;
                    int sec = (*sugar.begin()).second;
                    int e = min(sec,rem);
                    rem-=e;sec-=e;
                    all+=e;
                    if(sec!=0){
                        sugar.insert({pos,sec});
                    }
                }
                if(rem)ants.insert({-i[0],rem});
            }
        }
        cout<<all<<endl;
    }
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 504 KB Output is correct
2 Incorrect 1 ms 344 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Incorrect 0 ms 348 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 344 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 504 KB Output is correct
2 Incorrect 1 ms 344 KB Output isn't correct
3 Halted 0 ms 0 KB -