#include <bits/stdc++.h>
#define int ll
using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
#define rng(i,x,n) for(int i=x;i<n;i++)
#define per(i,n) for(int i=n-1;i>=0;i--)
#define fi first
#define se second
#define pb push_back
#define sz(a) (int)a.size()
#define vec(...) vector<__VA_ARGS__>
#define _3rfKJyA ios::sync_with_stdio(0),cin.tie(0)
typedef long long ll;
using pii=pair<int,int>;
using vi=vector<int>;
void print(){cout<<'\n';}
template<class h,class...t>
void print(const h&v,const t&...u){cout<<v<<' ',print(u...);}
// e
signed main(){
_3rfKJyA;
int q,lan;
cin>>q>>lan;
assert(q<=5000);
vec(pii) a,b,na,nb;
rep(_,q){
int t,x,c;
cin>>t>>x>>c;
if(t==1){
na.pb({x,c});
}else{
nb.pb({x,c});
}
a=na,b=nb;
sort(a.begin(),a.end());
sort(b.begin(),b.end());
int res=0,j=0;
for(int i=0;i<sz(a);i++){
if(j==sz(b) or b[j].fi-a[i].fi>lan){
continue;
}
while(j<sz(b) and a[i].fi-b[j].fi>lan){
j=j+1;
}
while(j<sz(b) and abs(a[i].fi-b[j].fi)<=lan and a[i].se){
int tk=min(a[i].se,b[j].se);
res+=tk;
a[i].se-=tk;
b[j].se-=tk;
if(b[j].se==0){
j=j+1;
}
}
}
print(res);
}
//
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
212 KB |
Output is correct |
3 |
Correct |
1 ms |
320 KB |
Output is correct |
4 |
Correct |
1 ms |
212 KB |
Output is correct |
5 |
Correct |
0 ms |
212 KB |
Output is correct |
6 |
Correct |
110 ms |
492 KB |
Output is correct |
7 |
Correct |
81 ms |
560 KB |
Output is correct |
8 |
Correct |
24 ms |
440 KB |
Output is correct |
9 |
Correct |
22 ms |
468 KB |
Output is correct |
10 |
Correct |
226 ms |
604 KB |
Output is correct |
11 |
Correct |
237 ms |
640 KB |
Output is correct |
12 |
Correct |
253 ms |
668 KB |
Output is correct |
13 |
Correct |
235 ms |
564 KB |
Output is correct |
14 |
Correct |
238 ms |
580 KB |
Output is correct |
15 |
Correct |
255 ms |
484 KB |
Output is correct |
16 |
Correct |
242 ms |
592 KB |
Output is correct |
17 |
Correct |
254 ms |
492 KB |
Output is correct |
18 |
Correct |
250 ms |
460 KB |
Output is correct |
19 |
Correct |
226 ms |
624 KB |
Output is correct |
20 |
Correct |
268 ms |
624 KB |
Output is correct |
21 |
Correct |
242 ms |
556 KB |
Output is correct |
22 |
Correct |
255 ms |
560 KB |
Output is correct |
23 |
Correct |
244 ms |
784 KB |
Output is correct |
24 |
Correct |
253 ms |
500 KB |
Output is correct |
25 |
Correct |
241 ms |
576 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
260 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
1 ms |
212 KB |
Output is correct |
4 |
Runtime error |
1 ms |
464 KB |
Execution killed with signal 6 |
5 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
328 KB |
Output is correct |
2 |
Runtime error |
1 ms |
460 KB |
Execution killed with signal 6 |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
212 KB |
Output is correct |
3 |
Correct |
1 ms |
320 KB |
Output is correct |
4 |
Correct |
1 ms |
212 KB |
Output is correct |
5 |
Correct |
0 ms |
212 KB |
Output is correct |
6 |
Correct |
110 ms |
492 KB |
Output is correct |
7 |
Correct |
81 ms |
560 KB |
Output is correct |
8 |
Correct |
24 ms |
440 KB |
Output is correct |
9 |
Correct |
22 ms |
468 KB |
Output is correct |
10 |
Correct |
226 ms |
604 KB |
Output is correct |
11 |
Correct |
237 ms |
640 KB |
Output is correct |
12 |
Correct |
253 ms |
668 KB |
Output is correct |
13 |
Correct |
235 ms |
564 KB |
Output is correct |
14 |
Correct |
238 ms |
580 KB |
Output is correct |
15 |
Correct |
255 ms |
484 KB |
Output is correct |
16 |
Correct |
242 ms |
592 KB |
Output is correct |
17 |
Correct |
254 ms |
492 KB |
Output is correct |
18 |
Correct |
250 ms |
460 KB |
Output is correct |
19 |
Correct |
226 ms |
624 KB |
Output is correct |
20 |
Correct |
268 ms |
624 KB |
Output is correct |
21 |
Correct |
242 ms |
556 KB |
Output is correct |
22 |
Correct |
255 ms |
560 KB |
Output is correct |
23 |
Correct |
244 ms |
784 KB |
Output is correct |
24 |
Correct |
253 ms |
500 KB |
Output is correct |
25 |
Correct |
241 ms |
576 KB |
Output is correct |
26 |
Correct |
1 ms |
260 KB |
Output is correct |
27 |
Correct |
0 ms |
212 KB |
Output is correct |
28 |
Correct |
1 ms |
212 KB |
Output is correct |
29 |
Runtime error |
1 ms |
464 KB |
Execution killed with signal 6 |
30 |
Halted |
0 ms |
0 KB |
- |