#include <iostream>
#include <algorithm>
#include <vector>
#define int long long
using namespace std;
int L;
int solve(vector<pair<int, int>> ant, vector<pair<int, int>> sugar)
{
int p1 = 0, p2 = 0, ans = 0;
while (p1 < (int)ant.size() && p2 < (int)sugar.size()) {
while (p1 < (int)ant.size() && ant[p1].first < sugar[p2].first - L) p1++;
if (p1 == (int)ant.size()) break;
if (ant[p1].first > sugar[p2].first + L) p2++;
else {
int match = min(ant[p1].second, sugar[p2].second);
ant[p1].second -= match;
sugar[p2].second -= match;
ans += match;
if (!ant[p1].second) p1++;
if (!sugar[p2].second) p2++;
}
}
return ans;
}
signed main()
{
ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
int Q; cin >> Q >> L;
vector<pair<int, int>> ant, sugar;
while (Q--) {
int t, x, a; cin >> t >> x >> a;
if (t == 1) ant.push_back(make_pair(x, a));
else sugar.push_back(make_pair(x, a));
sort(ant.begin(), ant.end());
sort(sugar.begin(), sugar.end());
cout << solve(ant, sugar) << '\n';
}
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
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 |
1 ms |
212 KB |
Output is correct |
5 |
Correct |
0 ms |
212 KB |
Output is correct |
6 |
Correct |
49 ms |
340 KB |
Output is correct |
7 |
Correct |
35 ms |
428 KB |
Output is correct |
8 |
Correct |
9 ms |
424 KB |
Output is correct |
9 |
Correct |
8 ms |
340 KB |
Output is correct |
10 |
Correct |
98 ms |
500 KB |
Output is correct |
11 |
Correct |
111 ms |
660 KB |
Output is correct |
12 |
Correct |
102 ms |
436 KB |
Output is correct |
13 |
Correct |
106 ms |
436 KB |
Output is correct |
14 |
Correct |
154 ms |
408 KB |
Output is correct |
15 |
Correct |
152 ms |
396 KB |
Output is correct |
16 |
Correct |
157 ms |
488 KB |
Output is correct |
17 |
Correct |
152 ms |
412 KB |
Output is correct |
18 |
Correct |
151 ms |
448 KB |
Output is correct |
19 |
Correct |
98 ms |
412 KB |
Output is correct |
20 |
Correct |
155 ms |
520 KB |
Output is correct |
21 |
Correct |
106 ms |
420 KB |
Output is correct |
22 |
Correct |
153 ms |
408 KB |
Output is correct |
23 |
Correct |
105 ms |
440 KB |
Output is correct |
24 |
Correct |
151 ms |
400 KB |
Output is correct |
25 |
Correct |
105 ms |
460 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
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 |
4062 ms |
976 KB |
Time limit exceeded |
5 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Execution timed out |
4019 ms |
804 KB |
Time limit exceeded |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
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 |
1 ms |
212 KB |
Output is correct |
5 |
Correct |
0 ms |
212 KB |
Output is correct |
6 |
Correct |
49 ms |
340 KB |
Output is correct |
7 |
Correct |
35 ms |
428 KB |
Output is correct |
8 |
Correct |
9 ms |
424 KB |
Output is correct |
9 |
Correct |
8 ms |
340 KB |
Output is correct |
10 |
Correct |
98 ms |
500 KB |
Output is correct |
11 |
Correct |
111 ms |
660 KB |
Output is correct |
12 |
Correct |
102 ms |
436 KB |
Output is correct |
13 |
Correct |
106 ms |
436 KB |
Output is correct |
14 |
Correct |
154 ms |
408 KB |
Output is correct |
15 |
Correct |
152 ms |
396 KB |
Output is correct |
16 |
Correct |
157 ms |
488 KB |
Output is correct |
17 |
Correct |
152 ms |
412 KB |
Output is correct |
18 |
Correct |
151 ms |
448 KB |
Output is correct |
19 |
Correct |
98 ms |
412 KB |
Output is correct |
20 |
Correct |
155 ms |
520 KB |
Output is correct |
21 |
Correct |
106 ms |
420 KB |
Output is correct |
22 |
Correct |
153 ms |
408 KB |
Output is correct |
23 |
Correct |
105 ms |
440 KB |
Output is correct |
24 |
Correct |
151 ms |
400 KB |
Output is correct |
25 |
Correct |
105 ms |
460 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 |
4062 ms |
976 KB |
Time limit exceeded |
30 |
Halted |
0 ms |
0 KB |
- |