#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(aa[i][1] && p < (int)bb.size() && aa[i][0] + l >= bb[p][0]){
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 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
1 ms |
212 KB |
Output is correct |
4 |
Correct |
1 ms |
212 KB |
Output is correct |
5 |
Correct |
1 ms |
212 KB |
Output is correct |
6 |
Correct |
196 ms |
592 KB |
Output is correct |
7 |
Correct |
154 ms |
664 KB |
Output is correct |
8 |
Correct |
43 ms |
452 KB |
Output is correct |
9 |
Correct |
38 ms |
416 KB |
Output is correct |
10 |
Correct |
424 ms |
804 KB |
Output is correct |
11 |
Correct |
421 ms |
776 KB |
Output is correct |
12 |
Correct |
454 ms |
764 KB |
Output is correct |
13 |
Correct |
461 ms |
772 KB |
Output is correct |
14 |
Correct |
501 ms |
772 KB |
Output is correct |
15 |
Correct |
497 ms |
756 KB |
Output is correct |
16 |
Correct |
529 ms |
756 KB |
Output is correct |
17 |
Correct |
495 ms |
796 KB |
Output is correct |
18 |
Correct |
500 ms |
704 KB |
Output is correct |
19 |
Correct |
478 ms |
776 KB |
Output is correct |
20 |
Correct |
517 ms |
656 KB |
Output is correct |
21 |
Correct |
442 ms |
744 KB |
Output is correct |
22 |
Correct |
537 ms |
856 KB |
Output is correct |
23 |
Correct |
440 ms |
756 KB |
Output is correct |
24 |
Correct |
510 ms |
720 KB |
Output is correct |
25 |
Correct |
461 ms |
776 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
212 KB |
Output is correct |
3 |
Correct |
1 ms |
212 KB |
Output is correct |
4 |
Execution timed out |
4067 ms |
1612 KB |
Time limit exceeded |
5 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Execution timed out |
4093 ms |
1364 KB |
Time limit exceeded |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 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 |
1 ms |
212 KB |
Output is correct |
5 |
Correct |
1 ms |
212 KB |
Output is correct |
6 |
Correct |
196 ms |
592 KB |
Output is correct |
7 |
Correct |
154 ms |
664 KB |
Output is correct |
8 |
Correct |
43 ms |
452 KB |
Output is correct |
9 |
Correct |
38 ms |
416 KB |
Output is correct |
10 |
Correct |
424 ms |
804 KB |
Output is correct |
11 |
Correct |
421 ms |
776 KB |
Output is correct |
12 |
Correct |
454 ms |
764 KB |
Output is correct |
13 |
Correct |
461 ms |
772 KB |
Output is correct |
14 |
Correct |
501 ms |
772 KB |
Output is correct |
15 |
Correct |
497 ms |
756 KB |
Output is correct |
16 |
Correct |
529 ms |
756 KB |
Output is correct |
17 |
Correct |
495 ms |
796 KB |
Output is correct |
18 |
Correct |
500 ms |
704 KB |
Output is correct |
19 |
Correct |
478 ms |
776 KB |
Output is correct |
20 |
Correct |
517 ms |
656 KB |
Output is correct |
21 |
Correct |
442 ms |
744 KB |
Output is correct |
22 |
Correct |
537 ms |
856 KB |
Output is correct |
23 |
Correct |
440 ms |
756 KB |
Output is correct |
24 |
Correct |
510 ms |
720 KB |
Output is correct |
25 |
Correct |
461 ms |
776 KB |
Output is correct |
26 |
Correct |
1 ms |
212 KB |
Output is correct |
27 |
Correct |
1 ms |
212 KB |
Output is correct |
28 |
Correct |
1 ms |
212 KB |
Output is correct |
29 |
Execution timed out |
4067 ms |
1612 KB |
Time limit exceeded |
30 |
Halted |
0 ms |
0 KB |
- |