#include <bits/stdc++.h>
#define int long long
using namespace std;
signed main(){
ios_base::sync_with_stdio(false);
cin.tie(0);
int q, l; cin >> q >> l;
vector<vector<int>> a, b;
while(q--){
int t, x, p; cin >> t >> x >> p;
if(t == 1){
a.push_back({x, p});
}
else{
b.push_back({x, p});
}
sort(a.begin(), a.end());
sort(b.begin(), b.end());
int ans = 0;
p = 0;
auto aa = a, bb = b;
for(int i = 0; i < (int)aa.size(); ++i){
while(p < (int)bb.size() && (!bb[p][1] || aa[i][0] - bb[p][0] > l)){
++p;
}
if(p < (int)bb.size() && abs(aa[i][0] - bb[p][0]) <= l){
int val = min(bb[p][1], aa[i][1]);
ans += val;
bb[p][1] -= val, aa[i][1] -= val;
}
}
cout << ans << '\n';
}
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Incorrect |
0 ms |
212 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Incorrect |
0 ms |
212 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
0 ms |
212 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Incorrect |
0 ms |
212 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |