#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;
ants.erase(ants.begin());
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;
sugar.erase(sugar.begin());
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;
}
}
# |
결과 |
실행 시간 |
메모리 |
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 |
- |
# |
결과 |
실행 시간 |
메모리 |
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 |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
0 ms |
348 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
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 |
- |