#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==1){
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 |
187 ms |
620 KB |
Output is correct |
7 |
Correct |
158 ms |
464 KB |
Output is correct |
8 |
Correct |
49 ms |
404 KB |
Output is correct |
9 |
Correct |
39 ms |
340 KB |
Output is correct |
10 |
Correct |
305 ms |
808 KB |
Output is correct |
11 |
Correct |
473 ms |
708 KB |
Output is correct |
12 |
Correct |
639 ms |
700 KB |
Output is correct |
13 |
Correct |
606 ms |
696 KB |
Output is correct |
14 |
Correct |
207 ms |
612 KB |
Output is correct |
15 |
Correct |
184 ms |
696 KB |
Output is correct |
16 |
Correct |
347 ms |
820 KB |
Output is correct |
17 |
Correct |
231 ms |
760 KB |
Output is correct |
18 |
Correct |
235 ms |
676 KB |
Output is correct |
19 |
Correct |
403 ms |
704 KB |
Output is correct |
20 |
Correct |
229 ms |
676 KB |
Output is correct |
21 |
Correct |
586 ms |
720 KB |
Output is correct |
22 |
Correct |
250 ms |
620 KB |
Output is correct |
23 |
Correct |
495 ms |
680 KB |
Output is correct |
24 |
Correct |
251 ms |
764 KB |
Output is correct |
25 |
Correct |
507 ms |
740 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 |
4075 ms |
1552 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 |
4075 ms |
1784 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 |
187 ms |
620 KB |
Output is correct |
7 |
Correct |
158 ms |
464 KB |
Output is correct |
8 |
Correct |
49 ms |
404 KB |
Output is correct |
9 |
Correct |
39 ms |
340 KB |
Output is correct |
10 |
Correct |
305 ms |
808 KB |
Output is correct |
11 |
Correct |
473 ms |
708 KB |
Output is correct |
12 |
Correct |
639 ms |
700 KB |
Output is correct |
13 |
Correct |
606 ms |
696 KB |
Output is correct |
14 |
Correct |
207 ms |
612 KB |
Output is correct |
15 |
Correct |
184 ms |
696 KB |
Output is correct |
16 |
Correct |
347 ms |
820 KB |
Output is correct |
17 |
Correct |
231 ms |
760 KB |
Output is correct |
18 |
Correct |
235 ms |
676 KB |
Output is correct |
19 |
Correct |
403 ms |
704 KB |
Output is correct |
20 |
Correct |
229 ms |
676 KB |
Output is correct |
21 |
Correct |
586 ms |
720 KB |
Output is correct |
22 |
Correct |
250 ms |
620 KB |
Output is correct |
23 |
Correct |
495 ms |
680 KB |
Output is correct |
24 |
Correct |
251 ms |
764 KB |
Output is correct |
25 |
Correct |
507 ms |
740 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 |
4075 ms |
1552 KB |
Time limit exceeded |
30 |
Halted |
0 ms |
0 KB |
- |