#include <bits/stdc++.h>
#define MAX 500005
#define MOD (ll)(1e9+7)
#define INF (ll)(1e18)
#define inf (1000000001)
using namespace std;
typedef long long ll;
typedef pair<ll, ll> pll;
typedef pair<int, int> pii;
int q, l;
map<int, ll> mp1, mp2;
int main()
{
ios::sync_with_stdio(false);
cin.tie(NULL);
cin >> q >> l;
while(q--) {
int t, a, b; cin >> t >> a >> b;
if(t == 1) mp1[a] += b;
else mp2[a] += b;
ll ans = 0;
auto ant = mp1, sugar = mp2;
for(auto it = ant.begin(); it != ant.end(); ++it) {
while(!sugar.empty() && (*it).second) {
if((*sugar.begin()).first - (*it).first > l) break;
else if(abs((*sugar.begin()).first - (*it).first) > l) sugar.erase(sugar.begin());
else if((*sugar.begin()).second <= (*it).second) {
ans += (*sugar.begin()).second;
(*it).second -= (*sugar.begin()).second;
sugar.erase(sugar.begin());
}
else {
ans += (*it).second;
(*sugar.begin()).second -= (*it).second;
(*it).second = 0;
}
}
}
cout << ans << '\n';
}
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
212 KB |
Output is correct |
3 |
Correct |
0 ms |
212 KB |
Output is correct |
4 |
Correct |
0 ms |
324 KB |
Output is correct |
5 |
Correct |
0 ms |
212 KB |
Output is correct |
6 |
Correct |
72 ms |
524 KB |
Output is correct |
7 |
Correct |
52 ms |
548 KB |
Output is correct |
8 |
Correct |
16 ms |
448 KB |
Output is correct |
9 |
Correct |
14 ms |
332 KB |
Output is correct |
10 |
Correct |
184 ms |
720 KB |
Output is correct |
11 |
Correct |
203 ms |
672 KB |
Output is correct |
12 |
Correct |
197 ms |
720 KB |
Output is correct |
13 |
Correct |
195 ms |
716 KB |
Output is correct |
14 |
Correct |
115 ms |
684 KB |
Output is correct |
15 |
Correct |
158 ms |
796 KB |
Output is correct |
16 |
Correct |
153 ms |
688 KB |
Output is correct |
17 |
Correct |
145 ms |
664 KB |
Output is correct |
18 |
Correct |
147 ms |
724 KB |
Output is correct |
19 |
Correct |
191 ms |
940 KB |
Output is correct |
20 |
Correct |
148 ms |
716 KB |
Output is correct |
21 |
Correct |
193 ms |
776 KB |
Output is correct |
22 |
Correct |
154 ms |
892 KB |
Output is correct |
23 |
Correct |
193 ms |
732 KB |
Output is correct |
24 |
Correct |
158 ms |
696 KB |
Output is correct |
25 |
Correct |
200 ms |
740 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 |
4045 ms |
2572 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 |
4043 ms |
2456 KB |
Time limit exceeded |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
212 KB |
Output is correct |
3 |
Correct |
0 ms |
212 KB |
Output is correct |
4 |
Correct |
0 ms |
324 KB |
Output is correct |
5 |
Correct |
0 ms |
212 KB |
Output is correct |
6 |
Correct |
72 ms |
524 KB |
Output is correct |
7 |
Correct |
52 ms |
548 KB |
Output is correct |
8 |
Correct |
16 ms |
448 KB |
Output is correct |
9 |
Correct |
14 ms |
332 KB |
Output is correct |
10 |
Correct |
184 ms |
720 KB |
Output is correct |
11 |
Correct |
203 ms |
672 KB |
Output is correct |
12 |
Correct |
197 ms |
720 KB |
Output is correct |
13 |
Correct |
195 ms |
716 KB |
Output is correct |
14 |
Correct |
115 ms |
684 KB |
Output is correct |
15 |
Correct |
158 ms |
796 KB |
Output is correct |
16 |
Correct |
153 ms |
688 KB |
Output is correct |
17 |
Correct |
145 ms |
664 KB |
Output is correct |
18 |
Correct |
147 ms |
724 KB |
Output is correct |
19 |
Correct |
191 ms |
940 KB |
Output is correct |
20 |
Correct |
148 ms |
716 KB |
Output is correct |
21 |
Correct |
193 ms |
776 KB |
Output is correct |
22 |
Correct |
154 ms |
892 KB |
Output is correct |
23 |
Correct |
193 ms |
732 KB |
Output is correct |
24 |
Correct |
158 ms |
696 KB |
Output is correct |
25 |
Correct |
200 ms |
740 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 |
4045 ms |
2572 KB |
Time limit exceeded |
30 |
Halted |
0 ms |
0 KB |
- |