Submission #545682

# Submission time Handle Problem Language Result Execution time Memory
545682 2022-04-05T07:35:59 Z leaked Ants and Sugar (JOI22_sugar) C++14
6 / 100
4000 ms 2072 KB
#include <bits/stdc++.h>

#define f first
#define s second
#define m_p make_pair
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()
#define vec vector
#define pb push_back
#define sz(x) (int)(x).size()
#define pw(x) (1LL<<(x))
#define fast_prep ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
typedef long double ld;
typedef pair<int,ll> pil;
template<class T> bool umin(T &a,const T &b){return (a>b?a=b,1:0);}
template<class T> bool umax(T &a,const T &b){return (a<b?a=b,1:0);}

signed main(){
    fast_prep;
    int n,k;
    cin>>n>>k;
    map<int,ll> x,y;
    auto solve=[&](){
        ll ans=0;
        map<int,ll> mp=y;
        map<int,ll> mpt=x;
        for(auto &z : mpt){
            while(z.s){
                auto it=mp.lower_bound(z.f-k);
                if(it==mp.end() || abs(it->f-z.f)>k) break;
                int j=it->f;
                ll mn=min(mp[j],z.s);
                ans+=mn;
                z.s-=mn;mp[j]-=mn;
                if(!mp[j]) mp.erase(j);
            }
        }
        return ans;
    };
    for(int i=0;i<n;i++){
        int t;
        cin>>t;
        if(t==2){
            int i,vl;
            cin>>i>>vl;
            x[i]+=vl;
        }
        else{
            int i,vl;
            cin>>i>>vl;
            y[i]+=vl;
        }
        cout<<solve()<<'\n';
    }
    return 0;
}
/*

*/
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 179 ms 536 KB Output is correct
7 Correct 169 ms 528 KB Output is correct
8 Correct 45 ms 432 KB Output is correct
9 Correct 35 ms 424 KB Output is correct
10 Correct 287 ms 648 KB Output is correct
11 Correct 509 ms 684 KB Output is correct
12 Correct 631 ms 720 KB Output is correct
13 Correct 588 ms 788 KB Output is correct
14 Correct 265 ms 744 KB Output is correct
15 Correct 245 ms 708 KB Output is correct
16 Correct 189 ms 660 KB Output is correct
17 Correct 198 ms 644 KB Output is correct
18 Correct 178 ms 680 KB Output is correct
19 Correct 349 ms 620 KB Output is correct
20 Correct 207 ms 740 KB Output is correct
21 Correct 536 ms 840 KB Output is correct
22 Correct 200 ms 596 KB Output is correct
23 Correct 479 ms 716 KB Output is correct
24 Correct 238 ms 692 KB Output is correct
25 Correct 481 ms 640 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Execution timed out 4064 ms 1768 KB Time limit exceeded
5 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Execution timed out 4059 ms 2072 KB Time limit exceeded
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 179 ms 536 KB Output is correct
7 Correct 169 ms 528 KB Output is correct
8 Correct 45 ms 432 KB Output is correct
9 Correct 35 ms 424 KB Output is correct
10 Correct 287 ms 648 KB Output is correct
11 Correct 509 ms 684 KB Output is correct
12 Correct 631 ms 720 KB Output is correct
13 Correct 588 ms 788 KB Output is correct
14 Correct 265 ms 744 KB Output is correct
15 Correct 245 ms 708 KB Output is correct
16 Correct 189 ms 660 KB Output is correct
17 Correct 198 ms 644 KB Output is correct
18 Correct 178 ms 680 KB Output is correct
19 Correct 349 ms 620 KB Output is correct
20 Correct 207 ms 740 KB Output is correct
21 Correct 536 ms 840 KB Output is correct
22 Correct 200 ms 596 KB Output is correct
23 Correct 479 ms 716 KB Output is correct
24 Correct 238 ms 692 KB Output is correct
25 Correct 481 ms 640 KB Output is correct
26 Correct 0 ms 212 KB Output is correct
27 Correct 0 ms 212 KB Output is correct
28 Correct 0 ms 212 KB Output is correct
29 Execution timed out 4064 ms 1768 KB Time limit exceeded
30 Halted 0 ms 0 KB -