#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define endl '\n'
#define INF 1e14+7
#define all(x) x.begin(),x.end()
using namespace std;
using namespace __gnu_pbds;
using ll=long long;
using pii=pair<int,int>;
using ppi=pair<int,pii>;
using oset=tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update>;
template<typename T>
void _print(vector<T> x) {cerr<<"{"; for(auto e:x) cerr<<e<<","; cerr<<"}";}
void _print(pii x) {cerr<<"{"<<x.first<<","<<x.second<<"}";}
template<typename T>
void _print(T x) {cerr<<x;}
void dbg() {cerr<<endl;}
template<typename Head,typename... Tail>
void dbg(Head H,Tail... T) {
_print(H);
if(sizeof...(T)) cerr<<",";
else cerr<<"\"]";
dbg(T...);
}
#define debug(...) cerr<<"["<<#__VA_ARGS__<<"]:[\"",dbg(__VA_ARGS__)
int n,d;
vector<ll> B;
struct dt {
int x,a,b;
bool operator<(const dt &r) {
return x<r.x;
};
};
vector<dt> shop;
ll ans = INF;
bool ok(ll f) {
ll sum=0;
ll f_rem=INF;
for(int i=0;i<n+1;i++) {
if(shop[i].b<f) continue;
f_rem=min(f_rem,f+sum-shop[i].x);
sum+=shop[i].a;
}
if(f_rem>=0) {
//ans=min(ans,f-f_rem);
cout<<f-f_rem<<endl; return true;
}
return false;
}
int main () {
ios::sync_with_stdio(false); cin.tie(0);
cin>>n>>d;
for(int i=0;i<n;i++) {
int x,a,b; cin>>x>>a>>b;
shop.push_back({x,a,b});
B.push_back(b);
}
B.push_back(d);
sort(all(shop)); shop.push_back({d,0,d});
sort(all(B)); B.erase(unique(all(B)),end(B));
for(auto e:B) {
if(ok(e)) {
return 0;
}
}
//cout<<ans<<endl;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
364 KB |
Output is correct |
2 |
Correct |
0 ms |
364 KB |
Output is correct |
3 |
Correct |
1 ms |
364 KB |
Output is correct |
4 |
Correct |
0 ms |
364 KB |
Output is correct |
5 |
Correct |
1 ms |
364 KB |
Output is correct |
6 |
Correct |
1 ms |
364 KB |
Output is correct |
7 |
Correct |
1 ms |
364 KB |
Output is correct |
8 |
Correct |
0 ms |
364 KB |
Output is correct |
9 |
Correct |
0 ms |
364 KB |
Output is correct |
10 |
Correct |
0 ms |
364 KB |
Output is correct |
11 |
Correct |
1 ms |
364 KB |
Output is correct |
12 |
Correct |
1 ms |
364 KB |
Output is correct |
13 |
Correct |
0 ms |
364 KB |
Output is correct |
14 |
Correct |
1 ms |
364 KB |
Output is correct |
15 |
Correct |
1 ms |
364 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
144 ms |
8812 KB |
Output is correct |
2 |
Correct |
148 ms |
8864 KB |
Output is correct |
3 |
Correct |
148 ms |
8812 KB |
Output is correct |
4 |
Correct |
140 ms |
8812 KB |
Output is correct |
5 |
Correct |
145 ms |
8728 KB |
Output is correct |
6 |
Correct |
173 ms |
8984 KB |
Output is correct |
7 |
Correct |
144 ms |
8816 KB |
Output is correct |
8 |
Correct |
138 ms |
8812 KB |
Output is correct |
9 |
Correct |
176 ms |
8812 KB |
Output is correct |
10 |
Correct |
140 ms |
8812 KB |
Output is correct |
11 |
Correct |
159 ms |
8812 KB |
Output is correct |
12 |
Correct |
158 ms |
8840 KB |
Output is correct |
13 |
Correct |
142 ms |
8864 KB |
Output is correct |
14 |
Correct |
161 ms |
8812 KB |
Output is correct |
15 |
Correct |
166 ms |
8812 KB |
Output is correct |
16 |
Correct |
146 ms |
8816 KB |
Output is correct |
17 |
Correct |
146 ms |
8812 KB |
Output is correct |
18 |
Correct |
148 ms |
8812 KB |
Output is correct |
19 |
Correct |
138 ms |
8812 KB |
Output is correct |
20 |
Correct |
153 ms |
8712 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
364 KB |
Output is correct |
2 |
Correct |
4 ms |
620 KB |
Output is correct |
3 |
Correct |
5 ms |
620 KB |
Output is correct |
4 |
Correct |
5 ms |
620 KB |
Output is correct |
5 |
Correct |
5 ms |
620 KB |
Output is correct |
6 |
Correct |
5 ms |
620 KB |
Output is correct |
7 |
Correct |
5 ms |
620 KB |
Output is correct |
8 |
Correct |
1 ms |
364 KB |
Output is correct |
9 |
Correct |
1 ms |
364 KB |
Output is correct |
10 |
Correct |
1 ms |
364 KB |
Output is correct |
11 |
Correct |
1 ms |
364 KB |
Output is correct |
12 |
Correct |
1 ms |
364 KB |
Output is correct |
13 |
Correct |
1 ms |
364 KB |
Output is correct |
14 |
Correct |
243 ms |
620 KB |
Output is correct |
15 |
Correct |
230 ms |
748 KB |
Output is correct |
16 |
Correct |
210 ms |
620 KB |
Output is correct |
17 |
Correct |
167 ms |
620 KB |
Output is correct |
18 |
Correct |
141 ms |
620 KB |
Output is correct |
19 |
Correct |
5 ms |
620 KB |
Output is correct |
20 |
Correct |
5 ms |
620 KB |
Output is correct |
21 |
Correct |
5 ms |
620 KB |
Output is correct |
22 |
Correct |
4 ms |
620 KB |
Output is correct |
23 |
Correct |
6 ms |
620 KB |
Output is correct |
24 |
Correct |
5 ms |
620 KB |
Output is correct |
25 |
Correct |
4 ms |
620 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
364 KB |
Output is correct |
2 |
Correct |
4 ms |
620 KB |
Output is correct |
3 |
Correct |
5 ms |
620 KB |
Output is correct |
4 |
Correct |
5 ms |
620 KB |
Output is correct |
5 |
Correct |
5 ms |
620 KB |
Output is correct |
6 |
Correct |
5 ms |
620 KB |
Output is correct |
7 |
Correct |
5 ms |
620 KB |
Output is correct |
8 |
Correct |
1 ms |
364 KB |
Output is correct |
9 |
Correct |
1 ms |
364 KB |
Output is correct |
10 |
Correct |
1 ms |
364 KB |
Output is correct |
11 |
Correct |
1 ms |
364 KB |
Output is correct |
12 |
Correct |
1 ms |
364 KB |
Output is correct |
13 |
Correct |
1 ms |
364 KB |
Output is correct |
14 |
Correct |
243 ms |
620 KB |
Output is correct |
15 |
Correct |
230 ms |
748 KB |
Output is correct |
16 |
Correct |
210 ms |
620 KB |
Output is correct |
17 |
Correct |
167 ms |
620 KB |
Output is correct |
18 |
Correct |
141 ms |
620 KB |
Output is correct |
19 |
Correct |
5 ms |
620 KB |
Output is correct |
20 |
Correct |
5 ms |
620 KB |
Output is correct |
21 |
Correct |
5 ms |
620 KB |
Output is correct |
22 |
Correct |
4 ms |
620 KB |
Output is correct |
23 |
Correct |
6 ms |
620 KB |
Output is correct |
24 |
Correct |
5 ms |
620 KB |
Output is correct |
25 |
Correct |
4 ms |
620 KB |
Output is correct |
26 |
Correct |
1 ms |
364 KB |
Output is correct |
27 |
Correct |
123 ms |
8812 KB |
Output is correct |
28 |
Correct |
123 ms |
8812 KB |
Output is correct |
29 |
Correct |
117 ms |
8964 KB |
Output is correct |
30 |
Correct |
121 ms |
8812 KB |
Output is correct |
31 |
Correct |
140 ms |
8812 KB |
Output is correct |
32 |
Correct |
129 ms |
12524 KB |
Output is correct |
33 |
Correct |
1 ms |
364 KB |
Output is correct |
34 |
Correct |
1 ms |
364 KB |
Output is correct |
35 |
Correct |
1 ms |
364 KB |
Output is correct |
36 |
Correct |
1 ms |
364 KB |
Output is correct |
37 |
Correct |
1 ms |
364 KB |
Output is correct |
38 |
Correct |
1 ms |
364 KB |
Output is correct |
39 |
Execution timed out |
3059 ms |
12780 KB |
Time limit exceeded |
40 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
364 KB |
Output is correct |
2 |
Correct |
0 ms |
364 KB |
Output is correct |
3 |
Correct |
1 ms |
364 KB |
Output is correct |
4 |
Correct |
0 ms |
364 KB |
Output is correct |
5 |
Correct |
1 ms |
364 KB |
Output is correct |
6 |
Correct |
1 ms |
364 KB |
Output is correct |
7 |
Correct |
1 ms |
364 KB |
Output is correct |
8 |
Correct |
0 ms |
364 KB |
Output is correct |
9 |
Correct |
0 ms |
364 KB |
Output is correct |
10 |
Correct |
0 ms |
364 KB |
Output is correct |
11 |
Correct |
1 ms |
364 KB |
Output is correct |
12 |
Correct |
1 ms |
364 KB |
Output is correct |
13 |
Correct |
0 ms |
364 KB |
Output is correct |
14 |
Correct |
1 ms |
364 KB |
Output is correct |
15 |
Correct |
1 ms |
364 KB |
Output is correct |
16 |
Correct |
0 ms |
364 KB |
Output is correct |
17 |
Correct |
0 ms |
364 KB |
Output is correct |
18 |
Correct |
0 ms |
364 KB |
Output is correct |
19 |
Correct |
1 ms |
364 KB |
Output is correct |
20 |
Correct |
1 ms |
364 KB |
Output is correct |
21 |
Correct |
1 ms |
364 KB |
Output is correct |
22 |
Correct |
1 ms |
364 KB |
Output is correct |
23 |
Correct |
1 ms |
364 KB |
Output is correct |
24 |
Correct |
1 ms |
364 KB |
Output is correct |
25 |
Correct |
1 ms |
364 KB |
Output is correct |
26 |
Correct |
1 ms |
364 KB |
Output is correct |
27 |
Correct |
0 ms |
364 KB |
Output is correct |
28 |
Correct |
1 ms |
364 KB |
Output is correct |
29 |
Correct |
1 ms |
364 KB |
Output is correct |
30 |
Correct |
0 ms |
364 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
364 KB |
Output is correct |
2 |
Correct |
0 ms |
364 KB |
Output is correct |
3 |
Correct |
1 ms |
364 KB |
Output is correct |
4 |
Correct |
0 ms |
364 KB |
Output is correct |
5 |
Correct |
1 ms |
364 KB |
Output is correct |
6 |
Correct |
1 ms |
364 KB |
Output is correct |
7 |
Correct |
1 ms |
364 KB |
Output is correct |
8 |
Correct |
0 ms |
364 KB |
Output is correct |
9 |
Correct |
0 ms |
364 KB |
Output is correct |
10 |
Correct |
0 ms |
364 KB |
Output is correct |
11 |
Correct |
1 ms |
364 KB |
Output is correct |
12 |
Correct |
1 ms |
364 KB |
Output is correct |
13 |
Correct |
0 ms |
364 KB |
Output is correct |
14 |
Correct |
1 ms |
364 KB |
Output is correct |
15 |
Correct |
1 ms |
364 KB |
Output is correct |
16 |
Correct |
1 ms |
364 KB |
Output is correct |
17 |
Correct |
4 ms |
620 KB |
Output is correct |
18 |
Correct |
5 ms |
620 KB |
Output is correct |
19 |
Correct |
5 ms |
620 KB |
Output is correct |
20 |
Correct |
5 ms |
620 KB |
Output is correct |
21 |
Correct |
5 ms |
620 KB |
Output is correct |
22 |
Correct |
5 ms |
620 KB |
Output is correct |
23 |
Correct |
1 ms |
364 KB |
Output is correct |
24 |
Correct |
1 ms |
364 KB |
Output is correct |
25 |
Correct |
1 ms |
364 KB |
Output is correct |
26 |
Correct |
1 ms |
364 KB |
Output is correct |
27 |
Correct |
1 ms |
364 KB |
Output is correct |
28 |
Correct |
1 ms |
364 KB |
Output is correct |
29 |
Correct |
243 ms |
620 KB |
Output is correct |
30 |
Correct |
230 ms |
748 KB |
Output is correct |
31 |
Correct |
210 ms |
620 KB |
Output is correct |
32 |
Correct |
167 ms |
620 KB |
Output is correct |
33 |
Correct |
141 ms |
620 KB |
Output is correct |
34 |
Correct |
5 ms |
620 KB |
Output is correct |
35 |
Correct |
5 ms |
620 KB |
Output is correct |
36 |
Correct |
5 ms |
620 KB |
Output is correct |
37 |
Correct |
4 ms |
620 KB |
Output is correct |
38 |
Correct |
6 ms |
620 KB |
Output is correct |
39 |
Correct |
5 ms |
620 KB |
Output is correct |
40 |
Correct |
4 ms |
620 KB |
Output is correct |
41 |
Correct |
1 ms |
364 KB |
Output is correct |
42 |
Correct |
5 ms |
620 KB |
Output is correct |
43 |
Correct |
6 ms |
620 KB |
Output is correct |
44 |
Correct |
6 ms |
620 KB |
Output is correct |
45 |
Correct |
6 ms |
620 KB |
Output is correct |
46 |
Correct |
7 ms |
620 KB |
Output is correct |
47 |
Correct |
5 ms |
620 KB |
Output is correct |
48 |
Correct |
1 ms |
364 KB |
Output is correct |
49 |
Correct |
1 ms |
364 KB |
Output is correct |
50 |
Correct |
1 ms |
364 KB |
Output is correct |
51 |
Correct |
1 ms |
384 KB |
Output is correct |
52 |
Correct |
0 ms |
364 KB |
Output is correct |
53 |
Correct |
1 ms |
364 KB |
Output is correct |
54 |
Correct |
358 ms |
620 KB |
Output is correct |
55 |
Correct |
262 ms |
620 KB |
Output is correct |
56 |
Correct |
382 ms |
620 KB |
Output is correct |
57 |
Correct |
366 ms |
620 KB |
Output is correct |
58 |
Correct |
309 ms |
620 KB |
Output is correct |
59 |
Correct |
9 ms |
620 KB |
Output is correct |
60 |
Correct |
5 ms |
620 KB |
Output is correct |
61 |
Correct |
5 ms |
620 KB |
Output is correct |
62 |
Correct |
5 ms |
860 KB |
Output is correct |
63 |
Correct |
8 ms |
620 KB |
Output is correct |
64 |
Correct |
6 ms |
620 KB |
Output is correct |
65 |
Correct |
5 ms |
620 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
364 KB |
Output is correct |
2 |
Correct |
0 ms |
364 KB |
Output is correct |
3 |
Correct |
1 ms |
364 KB |
Output is correct |
4 |
Correct |
0 ms |
364 KB |
Output is correct |
5 |
Correct |
1 ms |
364 KB |
Output is correct |
6 |
Correct |
1 ms |
364 KB |
Output is correct |
7 |
Correct |
1 ms |
364 KB |
Output is correct |
8 |
Correct |
0 ms |
364 KB |
Output is correct |
9 |
Correct |
0 ms |
364 KB |
Output is correct |
10 |
Correct |
0 ms |
364 KB |
Output is correct |
11 |
Correct |
1 ms |
364 KB |
Output is correct |
12 |
Correct |
1 ms |
364 KB |
Output is correct |
13 |
Correct |
0 ms |
364 KB |
Output is correct |
14 |
Correct |
1 ms |
364 KB |
Output is correct |
15 |
Correct |
1 ms |
364 KB |
Output is correct |
16 |
Correct |
144 ms |
8812 KB |
Output is correct |
17 |
Correct |
148 ms |
8864 KB |
Output is correct |
18 |
Correct |
148 ms |
8812 KB |
Output is correct |
19 |
Correct |
140 ms |
8812 KB |
Output is correct |
20 |
Correct |
145 ms |
8728 KB |
Output is correct |
21 |
Correct |
173 ms |
8984 KB |
Output is correct |
22 |
Correct |
144 ms |
8816 KB |
Output is correct |
23 |
Correct |
138 ms |
8812 KB |
Output is correct |
24 |
Correct |
176 ms |
8812 KB |
Output is correct |
25 |
Correct |
140 ms |
8812 KB |
Output is correct |
26 |
Correct |
159 ms |
8812 KB |
Output is correct |
27 |
Correct |
158 ms |
8840 KB |
Output is correct |
28 |
Correct |
142 ms |
8864 KB |
Output is correct |
29 |
Correct |
161 ms |
8812 KB |
Output is correct |
30 |
Correct |
166 ms |
8812 KB |
Output is correct |
31 |
Correct |
146 ms |
8816 KB |
Output is correct |
32 |
Correct |
146 ms |
8812 KB |
Output is correct |
33 |
Correct |
148 ms |
8812 KB |
Output is correct |
34 |
Correct |
138 ms |
8812 KB |
Output is correct |
35 |
Correct |
153 ms |
8712 KB |
Output is correct |
36 |
Correct |
1 ms |
364 KB |
Output is correct |
37 |
Correct |
4 ms |
620 KB |
Output is correct |
38 |
Correct |
5 ms |
620 KB |
Output is correct |
39 |
Correct |
5 ms |
620 KB |
Output is correct |
40 |
Correct |
5 ms |
620 KB |
Output is correct |
41 |
Correct |
5 ms |
620 KB |
Output is correct |
42 |
Correct |
5 ms |
620 KB |
Output is correct |
43 |
Correct |
1 ms |
364 KB |
Output is correct |
44 |
Correct |
1 ms |
364 KB |
Output is correct |
45 |
Correct |
1 ms |
364 KB |
Output is correct |
46 |
Correct |
1 ms |
364 KB |
Output is correct |
47 |
Correct |
1 ms |
364 KB |
Output is correct |
48 |
Correct |
1 ms |
364 KB |
Output is correct |
49 |
Correct |
243 ms |
620 KB |
Output is correct |
50 |
Correct |
230 ms |
748 KB |
Output is correct |
51 |
Correct |
210 ms |
620 KB |
Output is correct |
52 |
Correct |
167 ms |
620 KB |
Output is correct |
53 |
Correct |
141 ms |
620 KB |
Output is correct |
54 |
Correct |
5 ms |
620 KB |
Output is correct |
55 |
Correct |
5 ms |
620 KB |
Output is correct |
56 |
Correct |
5 ms |
620 KB |
Output is correct |
57 |
Correct |
4 ms |
620 KB |
Output is correct |
58 |
Correct |
6 ms |
620 KB |
Output is correct |
59 |
Correct |
5 ms |
620 KB |
Output is correct |
60 |
Correct |
4 ms |
620 KB |
Output is correct |
61 |
Correct |
1 ms |
364 KB |
Output is correct |
62 |
Correct |
123 ms |
8812 KB |
Output is correct |
63 |
Correct |
123 ms |
8812 KB |
Output is correct |
64 |
Correct |
117 ms |
8964 KB |
Output is correct |
65 |
Correct |
121 ms |
8812 KB |
Output is correct |
66 |
Correct |
140 ms |
8812 KB |
Output is correct |
67 |
Correct |
129 ms |
12524 KB |
Output is correct |
68 |
Correct |
1 ms |
364 KB |
Output is correct |
69 |
Correct |
1 ms |
364 KB |
Output is correct |
70 |
Correct |
1 ms |
364 KB |
Output is correct |
71 |
Correct |
1 ms |
364 KB |
Output is correct |
72 |
Correct |
1 ms |
364 KB |
Output is correct |
73 |
Correct |
1 ms |
364 KB |
Output is correct |
74 |
Execution timed out |
3059 ms |
12780 KB |
Time limit exceeded |
75 |
Halted |
0 ms |
0 KB |
- |