#include <bits/stdc++.h>
#define int long long
using namespace std;
typedef pair<int,int> ii;
#define ff first
#define ss second
const int maxn = 5e5 + 10;
int n,L;
multiset<ii> ms[2];
int query()
{
multiset<ii> nms[2];
nms[0]=ms[0]; nms[1]=ms[1];
int ans=0;
for (ii i:nms[0])
{
while (!nms[1].empty()&&nms[1].begin()->ff + L < i.ff) nms[1].erase(nms[1].begin());
while (i.ss>0&&!nms[1].empty()&&abs(i.ff-nms[1].begin()->ff) <= L)
{
auto it = nms[1].begin();
ii temp = *it;
int val = min(i.ss,temp.ss);
nms[1].erase(it);
ans+=val;
temp.ss-=val;
i.ss-=val;
if (temp.ss > 0) nms[1].insert(temp);
}
}
return ans;
}
signed main()
{
ios_base::sync_with_stdio(false);
cin.tie(nullptr); cout.tie(nullptr);
cin>>n>>L;
for (int i=0; i<n; i++)
{
int t; cin>>t;
if (t==1)
{
int x,y; cin>>x>>y;
ms[0].insert({x,y});
}
else
{
int x,y; cin>>x>>y;
ms[1].insert({x,y});
}
cout<<query()<<'\n';
}
}
# |
결과 |
실행 시간 |
메모리 |
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 |
135 ms |
580 KB |
Output is correct |
7 |
Correct |
99 ms |
568 KB |
Output is correct |
8 |
Correct |
38 ms |
412 KB |
Output is correct |
9 |
Correct |
27 ms |
392 KB |
Output is correct |
10 |
Correct |
269 ms |
960 KB |
Output is correct |
11 |
Correct |
347 ms |
716 KB |
Output is correct |
12 |
Correct |
324 ms |
868 KB |
Output is correct |
13 |
Correct |
332 ms |
832 KB |
Output is correct |
14 |
Correct |
186 ms |
640 KB |
Output is correct |
15 |
Correct |
240 ms |
772 KB |
Output is correct |
16 |
Correct |
241 ms |
752 KB |
Output is correct |
17 |
Correct |
234 ms |
684 KB |
Output is correct |
18 |
Correct |
241 ms |
784 KB |
Output is correct |
19 |
Correct |
281 ms |
712 KB |
Output is correct |
20 |
Correct |
246 ms |
724 KB |
Output is correct |
21 |
Correct |
376 ms |
744 KB |
Output is correct |
22 |
Correct |
252 ms |
672 KB |
Output is correct |
23 |
Correct |
374 ms |
760 KB |
Output is correct |
24 |
Correct |
256 ms |
756 KB |
Output is correct |
25 |
Correct |
372 ms |
708 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 |
4054 ms |
2072 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 |
4032 ms |
2640 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 |
135 ms |
580 KB |
Output is correct |
7 |
Correct |
99 ms |
568 KB |
Output is correct |
8 |
Correct |
38 ms |
412 KB |
Output is correct |
9 |
Correct |
27 ms |
392 KB |
Output is correct |
10 |
Correct |
269 ms |
960 KB |
Output is correct |
11 |
Correct |
347 ms |
716 KB |
Output is correct |
12 |
Correct |
324 ms |
868 KB |
Output is correct |
13 |
Correct |
332 ms |
832 KB |
Output is correct |
14 |
Correct |
186 ms |
640 KB |
Output is correct |
15 |
Correct |
240 ms |
772 KB |
Output is correct |
16 |
Correct |
241 ms |
752 KB |
Output is correct |
17 |
Correct |
234 ms |
684 KB |
Output is correct |
18 |
Correct |
241 ms |
784 KB |
Output is correct |
19 |
Correct |
281 ms |
712 KB |
Output is correct |
20 |
Correct |
246 ms |
724 KB |
Output is correct |
21 |
Correct |
376 ms |
744 KB |
Output is correct |
22 |
Correct |
252 ms |
672 KB |
Output is correct |
23 |
Correct |
374 ms |
760 KB |
Output is correct |
24 |
Correct |
256 ms |
756 KB |
Output is correct |
25 |
Correct |
372 ms |
708 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 |
4054 ms |
2072 KB |
Time limit exceeded |
30 |
Halted |
0 ms |
0 KB |
- |