#include <iostream>
#include <queue>
#include <vector>
#include <algorithm>
using namespace std;
const int Nmax=300000;
int n, d;
struct station{
int x, a, b;
}v[Nmax+1];
priority_queue <pair<int, int>, vector<pair<int, int>>, greater<pair<int, int>>> q;
bool cmp(station a, station b){
return a.x<b.x;
}
int main()
{
cin>>n>>d;
for (int i=0; i<n; i++)
cin>>v[i].x>>v[i].a>>v[i].b;
sort(v, v+n, cmp);
v[n].x=d; v[n].b=d+1;
int fs=0, fadd=0;
for (int i=0; i<=n; i++){
while (v[i].x>fs+fadd && fs<=v[i].b){
fs=v[i].x-fadd;
while (!q.empty() && q.top().first<fs){
fadd-=q.top().second;
q.pop();
}
}
if (fs<=v[i].b){
fadd+=v[i].a;
q.push({v[i].b, v[i].a});
}
}
cout<<fs;
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
0 ms |
308 KB |
Output is correct |
4 |
Correct |
0 ms |
308 KB |
Output is correct |
5 |
Correct |
1 ms |
212 KB |
Output is correct |
6 |
Correct |
0 ms |
212 KB |
Output is correct |
7 |
Correct |
1 ms |
212 KB |
Output is correct |
8 |
Correct |
0 ms |
212 KB |
Output is correct |
9 |
Correct |
0 ms |
212 KB |
Output is correct |
10 |
Correct |
0 ms |
212 KB |
Output is correct |
11 |
Correct |
0 ms |
212 KB |
Output is correct |
12 |
Correct |
0 ms |
212 KB |
Output is correct |
13 |
Correct |
0 ms |
308 KB |
Output is correct |
14 |
Correct |
1 ms |
212 KB |
Output is correct |
15 |
Correct |
0 ms |
212 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
276 ms |
12620 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
312 KB |
Output is correct |
2 |
Correct |
6 ms |
740 KB |
Output is correct |
3 |
Correct |
6 ms |
724 KB |
Output is correct |
4 |
Correct |
6 ms |
724 KB |
Output is correct |
5 |
Correct |
6 ms |
704 KB |
Output is correct |
6 |
Correct |
6 ms |
724 KB |
Output is correct |
7 |
Correct |
7 ms |
700 KB |
Output is correct |
8 |
Correct |
0 ms |
212 KB |
Output is correct |
9 |
Correct |
1 ms |
212 KB |
Output is correct |
10 |
Correct |
0 ms |
212 KB |
Output is correct |
11 |
Correct |
0 ms |
212 KB |
Output is correct |
12 |
Correct |
0 ms |
212 KB |
Output is correct |
13 |
Correct |
0 ms |
212 KB |
Output is correct |
14 |
Correct |
7 ms |
580 KB |
Output is correct |
15 |
Correct |
6 ms |
456 KB |
Output is correct |
16 |
Correct |
6 ms |
564 KB |
Output is correct |
17 |
Correct |
7 ms |
456 KB |
Output is correct |
18 |
Correct |
6 ms |
468 KB |
Output is correct |
19 |
Correct |
6 ms |
708 KB |
Output is correct |
20 |
Correct |
7 ms |
724 KB |
Output is correct |
21 |
Correct |
8 ms |
836 KB |
Output is correct |
22 |
Correct |
9 ms |
852 KB |
Output is correct |
23 |
Correct |
6 ms |
688 KB |
Output is correct |
24 |
Correct |
7 ms |
724 KB |
Output is correct |
25 |
Correct |
7 ms |
724 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
312 KB |
Output is correct |
2 |
Correct |
6 ms |
740 KB |
Output is correct |
3 |
Correct |
6 ms |
724 KB |
Output is correct |
4 |
Correct |
6 ms |
724 KB |
Output is correct |
5 |
Correct |
6 ms |
704 KB |
Output is correct |
6 |
Correct |
6 ms |
724 KB |
Output is correct |
7 |
Correct |
7 ms |
700 KB |
Output is correct |
8 |
Correct |
0 ms |
212 KB |
Output is correct |
9 |
Correct |
1 ms |
212 KB |
Output is correct |
10 |
Correct |
0 ms |
212 KB |
Output is correct |
11 |
Correct |
0 ms |
212 KB |
Output is correct |
12 |
Correct |
0 ms |
212 KB |
Output is correct |
13 |
Correct |
0 ms |
212 KB |
Output is correct |
14 |
Correct |
7 ms |
580 KB |
Output is correct |
15 |
Correct |
6 ms |
456 KB |
Output is correct |
16 |
Correct |
6 ms |
564 KB |
Output is correct |
17 |
Correct |
7 ms |
456 KB |
Output is correct |
18 |
Correct |
6 ms |
468 KB |
Output is correct |
19 |
Correct |
6 ms |
708 KB |
Output is correct |
20 |
Correct |
7 ms |
724 KB |
Output is correct |
21 |
Correct |
8 ms |
836 KB |
Output is correct |
22 |
Correct |
9 ms |
852 KB |
Output is correct |
23 |
Correct |
6 ms |
688 KB |
Output is correct |
24 |
Correct |
7 ms |
724 KB |
Output is correct |
25 |
Correct |
7 ms |
724 KB |
Output is correct |
26 |
Correct |
0 ms |
212 KB |
Output is correct |
27 |
Correct |
181 ms |
12256 KB |
Output is correct |
28 |
Correct |
184 ms |
12092 KB |
Output is correct |
29 |
Correct |
172 ms |
11836 KB |
Output is correct |
30 |
Correct |
171 ms |
11824 KB |
Output is correct |
31 |
Correct |
190 ms |
12364 KB |
Output is correct |
32 |
Correct |
186 ms |
12128 KB |
Output is correct |
33 |
Correct |
0 ms |
212 KB |
Output is correct |
34 |
Correct |
1 ms |
212 KB |
Output is correct |
35 |
Correct |
0 ms |
212 KB |
Output is correct |
36 |
Correct |
0 ms |
212 KB |
Output is correct |
37 |
Correct |
0 ms |
212 KB |
Output is correct |
38 |
Correct |
1 ms |
212 KB |
Output is correct |
39 |
Correct |
176 ms |
8152 KB |
Output is correct |
40 |
Correct |
183 ms |
8084 KB |
Output is correct |
41 |
Correct |
176 ms |
8128 KB |
Output is correct |
42 |
Correct |
175 ms |
8104 KB |
Output is correct |
43 |
Correct |
182 ms |
8012 KB |
Output is correct |
44 |
Correct |
169 ms |
8772 KB |
Output is correct |
45 |
Correct |
172 ms |
7452 KB |
Output is correct |
46 |
Correct |
186 ms |
12388 KB |
Output is correct |
47 |
Correct |
221 ms |
13884 KB |
Output is correct |
48 |
Correct |
219 ms |
13944 KB |
Output is correct |
49 |
Correct |
175 ms |
11664 KB |
Output is correct |
50 |
Correct |
174 ms |
12004 KB |
Output is correct |
51 |
Correct |
175 ms |
12104 KB |
Output is correct |
52 |
Correct |
171 ms |
11708 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
0 ms |
308 KB |
Output is correct |
4 |
Correct |
0 ms |
308 KB |
Output is correct |
5 |
Correct |
1 ms |
212 KB |
Output is correct |
6 |
Correct |
0 ms |
212 KB |
Output is correct |
7 |
Correct |
1 ms |
212 KB |
Output is correct |
8 |
Correct |
0 ms |
212 KB |
Output is correct |
9 |
Correct |
0 ms |
212 KB |
Output is correct |
10 |
Correct |
0 ms |
212 KB |
Output is correct |
11 |
Correct |
0 ms |
212 KB |
Output is correct |
12 |
Correct |
0 ms |
212 KB |
Output is correct |
13 |
Correct |
0 ms |
308 KB |
Output is correct |
14 |
Correct |
1 ms |
212 KB |
Output is correct |
15 |
Correct |
0 ms |
212 KB |
Output is correct |
16 |
Correct |
0 ms |
212 KB |
Output is correct |
17 |
Incorrect |
0 ms |
312 KB |
Output isn't correct |
18 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
0 ms |
308 KB |
Output is correct |
4 |
Correct |
0 ms |
308 KB |
Output is correct |
5 |
Correct |
1 ms |
212 KB |
Output is correct |
6 |
Correct |
0 ms |
212 KB |
Output is correct |
7 |
Correct |
1 ms |
212 KB |
Output is correct |
8 |
Correct |
0 ms |
212 KB |
Output is correct |
9 |
Correct |
0 ms |
212 KB |
Output is correct |
10 |
Correct |
0 ms |
212 KB |
Output is correct |
11 |
Correct |
0 ms |
212 KB |
Output is correct |
12 |
Correct |
0 ms |
212 KB |
Output is correct |
13 |
Correct |
0 ms |
308 KB |
Output is correct |
14 |
Correct |
1 ms |
212 KB |
Output is correct |
15 |
Correct |
0 ms |
212 KB |
Output is correct |
16 |
Correct |
1 ms |
312 KB |
Output is correct |
17 |
Correct |
6 ms |
740 KB |
Output is correct |
18 |
Correct |
6 ms |
724 KB |
Output is correct |
19 |
Correct |
6 ms |
724 KB |
Output is correct |
20 |
Correct |
6 ms |
704 KB |
Output is correct |
21 |
Correct |
6 ms |
724 KB |
Output is correct |
22 |
Correct |
7 ms |
700 KB |
Output is correct |
23 |
Correct |
0 ms |
212 KB |
Output is correct |
24 |
Correct |
1 ms |
212 KB |
Output is correct |
25 |
Correct |
0 ms |
212 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 |
Correct |
7 ms |
580 KB |
Output is correct |
30 |
Correct |
6 ms |
456 KB |
Output is correct |
31 |
Correct |
6 ms |
564 KB |
Output is correct |
32 |
Correct |
7 ms |
456 KB |
Output is correct |
33 |
Correct |
6 ms |
468 KB |
Output is correct |
34 |
Correct |
6 ms |
708 KB |
Output is correct |
35 |
Correct |
7 ms |
724 KB |
Output is correct |
36 |
Correct |
8 ms |
836 KB |
Output is correct |
37 |
Correct |
9 ms |
852 KB |
Output is correct |
38 |
Correct |
6 ms |
688 KB |
Output is correct |
39 |
Correct |
7 ms |
724 KB |
Output is correct |
40 |
Correct |
7 ms |
724 KB |
Output is correct |
41 |
Correct |
0 ms |
212 KB |
Output is correct |
42 |
Incorrect |
8 ms |
576 KB |
Output isn't correct |
43 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
0 ms |
308 KB |
Output is correct |
4 |
Correct |
0 ms |
308 KB |
Output is correct |
5 |
Correct |
1 ms |
212 KB |
Output is correct |
6 |
Correct |
0 ms |
212 KB |
Output is correct |
7 |
Correct |
1 ms |
212 KB |
Output is correct |
8 |
Correct |
0 ms |
212 KB |
Output is correct |
9 |
Correct |
0 ms |
212 KB |
Output is correct |
10 |
Correct |
0 ms |
212 KB |
Output is correct |
11 |
Correct |
0 ms |
212 KB |
Output is correct |
12 |
Correct |
0 ms |
212 KB |
Output is correct |
13 |
Correct |
0 ms |
308 KB |
Output is correct |
14 |
Correct |
1 ms |
212 KB |
Output is correct |
15 |
Correct |
0 ms |
212 KB |
Output is correct |
16 |
Incorrect |
276 ms |
12620 KB |
Output isn't correct |
17 |
Halted |
0 ms |
0 KB |
- |