답안 #545681

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
545681 2022-04-05T07:35:09 Z leaked Ants and Sugar (JOI22_sugar) C++14
6 / 100
4000 ms 2264 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 int long long
#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,int> x,y;
    auto solve=[&](){
        ll ans=0;
        map<int,int> mp=y;
        map<int,int> 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;
                int 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;
}
/*

*/
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 1 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 184 ms 552 KB Output is correct
7 Correct 156 ms 460 KB Output is correct
8 Correct 47 ms 416 KB Output is correct
9 Correct 35 ms 420 KB Output is correct
10 Correct 301 ms 680 KB Output is correct
11 Correct 464 ms 840 KB Output is correct
12 Correct 627 ms 688 KB Output is correct
13 Correct 594 ms 740 KB Output is correct
14 Correct 234 ms 596 KB Output is correct
15 Correct 250 ms 620 KB Output is correct
16 Correct 234 ms 588 KB Output is correct
17 Correct 185 ms 632 KB Output is correct
18 Correct 188 ms 568 KB Output is correct
19 Correct 393 ms 596 KB Output is correct
20 Correct 183 ms 580 KB Output is correct
21 Correct 575 ms 704 KB Output is correct
22 Correct 178 ms 656 KB Output is correct
23 Correct 567 ms 744 KB Output is correct
24 Correct 186 ms 680 KB Output is correct
25 Correct 509 ms 744 KB Output is correct
# 결과 실행 시간 메모리 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 4048 ms 1732 KB Time limit exceeded
5 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Execution timed out 4046 ms 2264 KB Time limit exceeded
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 1 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 184 ms 552 KB Output is correct
7 Correct 156 ms 460 KB Output is correct
8 Correct 47 ms 416 KB Output is correct
9 Correct 35 ms 420 KB Output is correct
10 Correct 301 ms 680 KB Output is correct
11 Correct 464 ms 840 KB Output is correct
12 Correct 627 ms 688 KB Output is correct
13 Correct 594 ms 740 KB Output is correct
14 Correct 234 ms 596 KB Output is correct
15 Correct 250 ms 620 KB Output is correct
16 Correct 234 ms 588 KB Output is correct
17 Correct 185 ms 632 KB Output is correct
18 Correct 188 ms 568 KB Output is correct
19 Correct 393 ms 596 KB Output is correct
20 Correct 183 ms 580 KB Output is correct
21 Correct 575 ms 704 KB Output is correct
22 Correct 178 ms 656 KB Output is correct
23 Correct 567 ms 744 KB Output is correct
24 Correct 186 ms 680 KB Output is correct
25 Correct 509 ms 744 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 4048 ms 1732 KB Time limit exceeded
30 Halted 0 ms 0 KB -