#include <bits/stdc++.h>
#define ll long long
#define ull unsigned ll
#define f first
#define s second
#define pii pair<int,int>
#define pll pair<ll,ll>
#define pb push_back
#define epb emplace_back
using namespace std;
const int nmax = 10000001;
vector <ll> bit(nmax);
const ll mod = 1e9 + 7;
int lsb(int x){
return x & -x;
}
void add(int pos, ll v, int n){
while(pos <= n){
bit[pos] += v;
pos += lsb(pos);
}
}
ll get(int pos){
ll res = 0;
while(pos){
res += bit[pos];
pos -= lsb(pos);
}
return res;
}
vector <ll> t(4 * nmax), lazy(4 * nmax);
void push(int v){
t[2 * v] += lazy[v];
lazy[2 * v] += lazy[v];
t[2 * v + 1] += lazy[v];
lazy[2 * v + 1] += lazy[v];
lazy[v] = 0;
}
void upd(int v, int l, int r, int pos, ll val){
if(l > pos || r < pos)
return;
if(l == r){
t[v] = val;
return;
}
int m = (l + r) / 2;
push(v);
upd(2 * v, l, m, pos, val);
upd(2 * v + 1, m + 1,r, pos, val);
t[v] = max(t[2 * v], t[2 * v + 1]);
}
void upd_ran(int v, int l, int r, int st, int fin, ll val){
if(l > fin || r < st)
return;
if(l >= st && r <= fin){
t[v] += val;
lazy[v] += val;
return;
}
int m = (l + r) / 2;
push(v);
upd_ran(2 * v, l, m, st, fin, val);
upd_ran(2 * v + 1, m + 1, r, st, fin, val);
t[v] = max(t[2 * v], t[2 * v + 1]);
}
int main(){
int n; cin >> n;
int d; cin >> d;
ll a[n + 1], b[n + 1];
ll x[n + 1];
ll pos[n + 2];
for(int i = 1; i <= n; i++)
cin >> x[i] >> a[i] >> b[i];
map <int,int> mp;
vector <pll> cmp;
for(int i= 1; i <= n; i++){
cmp.pb({x[i], i});
}
cmp.pb({d, 0});
sort(cmp.begin(), cmp.end());
for(int i= 0; i < cmp.size(); i++)
pos[cmp[i].s] = i + 1;
vector <pll> B;
for(int i = 1; i <=n; i++){
B.pb({b[i], i});
}
sort(B.begin(), B.end());
upd(1, 1, n + 1, n + 1, d);
ll ans = d;
for(int i = 0; i < B.size(); i++){
int p = B[i].s;
ll xx = get(pos[p] - 1);
upd(1, 1, n + 1, pos[p], x[p] - xx);
upd_ran(1, 1, n + 1, pos[p] + 1, n + 1, -a[p]);
add(pos[p], a[p], n + 1);
if(B[i].f >= t[1]){
ans = min(t[1], ans);
continue;
}
}
cout << max(ans, 0LL);
return 0;
}
Compilation message
FuelStation.cpp: In function 'int main()':
FuelStation.cpp:93:21: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<long long int, long long int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
93 | for(int i= 0; i < cmp.size(); i++)
| ~~^~~~~~~~~~~~
FuelStation.cpp:103:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<long long int, long long int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
103 | for(int i = 0; i < B.size(); i++){
| ~~^~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
255 ms |
704740 KB |
Output is correct |
2 |
Correct |
252 ms |
704836 KB |
Output is correct |
3 |
Correct |
253 ms |
704844 KB |
Output is correct |
4 |
Correct |
250 ms |
704800 KB |
Output is correct |
5 |
Correct |
252 ms |
704712 KB |
Output is correct |
6 |
Correct |
249 ms |
704780 KB |
Output is correct |
7 |
Correct |
244 ms |
704716 KB |
Output is correct |
8 |
Correct |
248 ms |
704732 KB |
Output is correct |
9 |
Correct |
252 ms |
704760 KB |
Output is correct |
10 |
Correct |
245 ms |
704716 KB |
Output is correct |
11 |
Correct |
249 ms |
704760 KB |
Output is correct |
12 |
Correct |
266 ms |
704752 KB |
Output is correct |
13 |
Correct |
276 ms |
704716 KB |
Output is correct |
14 |
Correct |
265 ms |
704796 KB |
Output is correct |
15 |
Correct |
268 ms |
704692 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
865 ms |
737716 KB |
Output is correct |
2 |
Correct |
861 ms |
737412 KB |
Output is correct |
3 |
Correct |
841 ms |
737168 KB |
Output is correct |
4 |
Correct |
836 ms |
737084 KB |
Output is correct |
5 |
Correct |
806 ms |
736472 KB |
Output is correct |
6 |
Correct |
805 ms |
736576 KB |
Output is correct |
7 |
Correct |
810 ms |
735880 KB |
Output is correct |
8 |
Correct |
784 ms |
735108 KB |
Output is correct |
9 |
Correct |
846 ms |
734504 KB |
Output is correct |
10 |
Correct |
770 ms |
734524 KB |
Output is correct |
11 |
Correct |
802 ms |
734264 KB |
Output is correct |
12 |
Correct |
796 ms |
733668 KB |
Output is correct |
13 |
Correct |
834 ms |
733432 KB |
Output is correct |
14 |
Correct |
844 ms |
733176 KB |
Output is correct |
15 |
Correct |
866 ms |
732780 KB |
Output is correct |
16 |
Correct |
885 ms |
732572 KB |
Output is correct |
17 |
Correct |
808 ms |
732228 KB |
Output is correct |
18 |
Correct |
830 ms |
732072 KB |
Output is correct |
19 |
Correct |
793 ms |
731848 KB |
Output is correct |
20 |
Correct |
857 ms |
731572 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
254 ms |
704808 KB |
Output is correct |
2 |
Correct |
268 ms |
705776 KB |
Output is correct |
3 |
Correct |
293 ms |
705748 KB |
Output is correct |
4 |
Correct |
261 ms |
705704 KB |
Output is correct |
5 |
Correct |
271 ms |
705836 KB |
Output is correct |
6 |
Correct |
262 ms |
705776 KB |
Output is correct |
7 |
Correct |
296 ms |
705704 KB |
Output is correct |
8 |
Incorrect |
252 ms |
704732 KB |
Output isn't correct |
9 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
254 ms |
704808 KB |
Output is correct |
2 |
Correct |
268 ms |
705776 KB |
Output is correct |
3 |
Correct |
293 ms |
705748 KB |
Output is correct |
4 |
Correct |
261 ms |
705704 KB |
Output is correct |
5 |
Correct |
271 ms |
705836 KB |
Output is correct |
6 |
Correct |
262 ms |
705776 KB |
Output is correct |
7 |
Correct |
296 ms |
705704 KB |
Output is correct |
8 |
Incorrect |
252 ms |
704732 KB |
Output isn't correct |
9 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
255 ms |
704740 KB |
Output is correct |
2 |
Correct |
252 ms |
704836 KB |
Output is correct |
3 |
Correct |
253 ms |
704844 KB |
Output is correct |
4 |
Correct |
250 ms |
704800 KB |
Output is correct |
5 |
Correct |
252 ms |
704712 KB |
Output is correct |
6 |
Correct |
249 ms |
704780 KB |
Output is correct |
7 |
Correct |
244 ms |
704716 KB |
Output is correct |
8 |
Correct |
248 ms |
704732 KB |
Output is correct |
9 |
Correct |
252 ms |
704760 KB |
Output is correct |
10 |
Correct |
245 ms |
704716 KB |
Output is correct |
11 |
Correct |
249 ms |
704760 KB |
Output is correct |
12 |
Correct |
266 ms |
704752 KB |
Output is correct |
13 |
Correct |
276 ms |
704716 KB |
Output is correct |
14 |
Correct |
265 ms |
704796 KB |
Output is correct |
15 |
Correct |
268 ms |
704692 KB |
Output is correct |
16 |
Correct |
253 ms |
704716 KB |
Output is correct |
17 |
Correct |
259 ms |
704772 KB |
Output is correct |
18 |
Correct |
251 ms |
704716 KB |
Output is correct |
19 |
Correct |
255 ms |
704804 KB |
Output is correct |
20 |
Correct |
252 ms |
704732 KB |
Output is correct |
21 |
Correct |
258 ms |
704760 KB |
Output is correct |
22 |
Incorrect |
250 ms |
704716 KB |
Output isn't correct |
23 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
255 ms |
704740 KB |
Output is correct |
2 |
Correct |
252 ms |
704836 KB |
Output is correct |
3 |
Correct |
253 ms |
704844 KB |
Output is correct |
4 |
Correct |
250 ms |
704800 KB |
Output is correct |
5 |
Correct |
252 ms |
704712 KB |
Output is correct |
6 |
Correct |
249 ms |
704780 KB |
Output is correct |
7 |
Correct |
244 ms |
704716 KB |
Output is correct |
8 |
Correct |
248 ms |
704732 KB |
Output is correct |
9 |
Correct |
252 ms |
704760 KB |
Output is correct |
10 |
Correct |
245 ms |
704716 KB |
Output is correct |
11 |
Correct |
249 ms |
704760 KB |
Output is correct |
12 |
Correct |
266 ms |
704752 KB |
Output is correct |
13 |
Correct |
276 ms |
704716 KB |
Output is correct |
14 |
Correct |
265 ms |
704796 KB |
Output is correct |
15 |
Correct |
268 ms |
704692 KB |
Output is correct |
16 |
Correct |
254 ms |
704808 KB |
Output is correct |
17 |
Correct |
268 ms |
705776 KB |
Output is correct |
18 |
Correct |
293 ms |
705748 KB |
Output is correct |
19 |
Correct |
261 ms |
705704 KB |
Output is correct |
20 |
Correct |
271 ms |
705836 KB |
Output is correct |
21 |
Correct |
262 ms |
705776 KB |
Output is correct |
22 |
Correct |
296 ms |
705704 KB |
Output is correct |
23 |
Incorrect |
252 ms |
704732 KB |
Output isn't correct |
24 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
255 ms |
704740 KB |
Output is correct |
2 |
Correct |
252 ms |
704836 KB |
Output is correct |
3 |
Correct |
253 ms |
704844 KB |
Output is correct |
4 |
Correct |
250 ms |
704800 KB |
Output is correct |
5 |
Correct |
252 ms |
704712 KB |
Output is correct |
6 |
Correct |
249 ms |
704780 KB |
Output is correct |
7 |
Correct |
244 ms |
704716 KB |
Output is correct |
8 |
Correct |
248 ms |
704732 KB |
Output is correct |
9 |
Correct |
252 ms |
704760 KB |
Output is correct |
10 |
Correct |
245 ms |
704716 KB |
Output is correct |
11 |
Correct |
249 ms |
704760 KB |
Output is correct |
12 |
Correct |
266 ms |
704752 KB |
Output is correct |
13 |
Correct |
276 ms |
704716 KB |
Output is correct |
14 |
Correct |
265 ms |
704796 KB |
Output is correct |
15 |
Correct |
268 ms |
704692 KB |
Output is correct |
16 |
Correct |
865 ms |
737716 KB |
Output is correct |
17 |
Correct |
861 ms |
737412 KB |
Output is correct |
18 |
Correct |
841 ms |
737168 KB |
Output is correct |
19 |
Correct |
836 ms |
737084 KB |
Output is correct |
20 |
Correct |
806 ms |
736472 KB |
Output is correct |
21 |
Correct |
805 ms |
736576 KB |
Output is correct |
22 |
Correct |
810 ms |
735880 KB |
Output is correct |
23 |
Correct |
784 ms |
735108 KB |
Output is correct |
24 |
Correct |
846 ms |
734504 KB |
Output is correct |
25 |
Correct |
770 ms |
734524 KB |
Output is correct |
26 |
Correct |
802 ms |
734264 KB |
Output is correct |
27 |
Correct |
796 ms |
733668 KB |
Output is correct |
28 |
Correct |
834 ms |
733432 KB |
Output is correct |
29 |
Correct |
844 ms |
733176 KB |
Output is correct |
30 |
Correct |
866 ms |
732780 KB |
Output is correct |
31 |
Correct |
885 ms |
732572 KB |
Output is correct |
32 |
Correct |
808 ms |
732228 KB |
Output is correct |
33 |
Correct |
830 ms |
732072 KB |
Output is correct |
34 |
Correct |
793 ms |
731848 KB |
Output is correct |
35 |
Correct |
857 ms |
731572 KB |
Output is correct |
36 |
Correct |
254 ms |
704808 KB |
Output is correct |
37 |
Correct |
268 ms |
705776 KB |
Output is correct |
38 |
Correct |
293 ms |
705748 KB |
Output is correct |
39 |
Correct |
261 ms |
705704 KB |
Output is correct |
40 |
Correct |
271 ms |
705836 KB |
Output is correct |
41 |
Correct |
262 ms |
705776 KB |
Output is correct |
42 |
Correct |
296 ms |
705704 KB |
Output is correct |
43 |
Incorrect |
252 ms |
704732 KB |
Output isn't correct |
44 |
Halted |
0 ms |
0 KB |
- |