#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;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
364 KB |
Output is correct |
2 |
Correct |
1 ms |
364 KB |
Output is correct |
3 |
Correct |
1 ms |
364 KB |
Output is correct |
4 |
Correct |
1 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 |
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 |
1 ms |
364 KB |
Output is correct |
15 |
Correct |
1 ms |
364 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
157 ms |
8812 KB |
Output is correct |
2 |
Correct |
152 ms |
8812 KB |
Output is correct |
3 |
Correct |
157 ms |
8836 KB |
Output is correct |
4 |
Correct |
150 ms |
8812 KB |
Output is correct |
5 |
Correct |
165 ms |
8812 KB |
Output is correct |
6 |
Correct |
159 ms |
8812 KB |
Output is correct |
7 |
Correct |
154 ms |
8812 KB |
Output is correct |
8 |
Correct |
148 ms |
8748 KB |
Output is correct |
9 |
Correct |
153 ms |
8812 KB |
Output is correct |
10 |
Correct |
152 ms |
8812 KB |
Output is correct |
11 |
Correct |
159 ms |
8808 KB |
Output is correct |
12 |
Correct |
160 ms |
8756 KB |
Output is correct |
13 |
Correct |
144 ms |
8812 KB |
Output is correct |
14 |
Correct |
168 ms |
8812 KB |
Output is correct |
15 |
Correct |
171 ms |
8960 KB |
Output is correct |
16 |
Correct |
149 ms |
8812 KB |
Output is correct |
17 |
Correct |
152 ms |
8812 KB |
Output is correct |
18 |
Correct |
170 ms |
8812 KB |
Output is correct |
19 |
Correct |
143 ms |
8812 KB |
Output is correct |
20 |
Correct |
147 ms |
8812 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
364 KB |
Output is correct |
2 |
Correct |
38 ms |
840 KB |
Output is correct |
3 |
Correct |
44 ms |
840 KB |
Output is correct |
4 |
Correct |
42 ms |
748 KB |
Output is correct |
5 |
Correct |
39 ms |
888 KB |
Output is correct |
6 |
Correct |
344 ms |
840 KB |
Output is correct |
7 |
Correct |
347 ms |
840 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 |
245 ms |
868 KB |
Output is correct |
15 |
Correct |
230 ms |
840 KB |
Output is correct |
16 |
Correct |
213 ms |
840 KB |
Output is correct |
17 |
Correct |
178 ms |
868 KB |
Output is correct |
18 |
Correct |
147 ms |
840 KB |
Output is correct |
19 |
Correct |
39 ms |
876 KB |
Output is correct |
20 |
Correct |
5 ms |
896 KB |
Output is correct |
21 |
Correct |
5 ms |
876 KB |
Output is correct |
22 |
Correct |
8 ms |
840 KB |
Output is correct |
23 |
Correct |
9 ms |
840 KB |
Output is correct |
24 |
Correct |
42 ms |
876 KB |
Output is correct |
25 |
Correct |
8 ms |
748 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
364 KB |
Output is correct |
2 |
Correct |
38 ms |
840 KB |
Output is correct |
3 |
Correct |
44 ms |
840 KB |
Output is correct |
4 |
Correct |
42 ms |
748 KB |
Output is correct |
5 |
Correct |
39 ms |
888 KB |
Output is correct |
6 |
Correct |
344 ms |
840 KB |
Output is correct |
7 |
Correct |
347 ms |
840 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 |
245 ms |
868 KB |
Output is correct |
15 |
Correct |
230 ms |
840 KB |
Output is correct |
16 |
Correct |
213 ms |
840 KB |
Output is correct |
17 |
Correct |
178 ms |
868 KB |
Output is correct |
18 |
Correct |
147 ms |
840 KB |
Output is correct |
19 |
Correct |
39 ms |
876 KB |
Output is correct |
20 |
Correct |
5 ms |
896 KB |
Output is correct |
21 |
Correct |
5 ms |
876 KB |
Output is correct |
22 |
Correct |
8 ms |
840 KB |
Output is correct |
23 |
Correct |
9 ms |
840 KB |
Output is correct |
24 |
Correct |
42 ms |
876 KB |
Output is correct |
25 |
Correct |
8 ms |
748 KB |
Output is correct |
26 |
Correct |
1 ms |
364 KB |
Output is correct |
27 |
Correct |
753 ms |
12912 KB |
Output is correct |
28 |
Correct |
1164 ms |
12556 KB |
Output is correct |
29 |
Correct |
1167 ms |
12268 KB |
Output is correct |
30 |
Correct |
1164 ms |
12268 KB |
Output is correct |
31 |
Execution timed out |
3058 ms |
12744 KB |
Time limit exceeded |
32 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
364 KB |
Output is correct |
2 |
Correct |
1 ms |
364 KB |
Output is correct |
3 |
Correct |
1 ms |
364 KB |
Output is correct |
4 |
Correct |
1 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 |
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 |
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 |
1 ms |
364 KB |
Output is correct |
18 |
Correct |
1 ms |
364 KB |
Output is correct |
19 |
Correct |
1 ms |
364 KB |
Output is correct |
20 |
Correct |
1 ms |
508 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 |
492 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 |
1 ms |
364 KB |
Output is correct |
30 |
Correct |
1 ms |
364 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
364 KB |
Output is correct |
2 |
Correct |
1 ms |
364 KB |
Output is correct |
3 |
Correct |
1 ms |
364 KB |
Output is correct |
4 |
Correct |
1 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 |
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 |
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 |
38 ms |
840 KB |
Output is correct |
18 |
Correct |
44 ms |
840 KB |
Output is correct |
19 |
Correct |
42 ms |
748 KB |
Output is correct |
20 |
Correct |
39 ms |
888 KB |
Output is correct |
21 |
Correct |
344 ms |
840 KB |
Output is correct |
22 |
Correct |
347 ms |
840 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 |
245 ms |
868 KB |
Output is correct |
30 |
Correct |
230 ms |
840 KB |
Output is correct |
31 |
Correct |
213 ms |
840 KB |
Output is correct |
32 |
Correct |
178 ms |
868 KB |
Output is correct |
33 |
Correct |
147 ms |
840 KB |
Output is correct |
34 |
Correct |
39 ms |
876 KB |
Output is correct |
35 |
Correct |
5 ms |
896 KB |
Output is correct |
36 |
Correct |
5 ms |
876 KB |
Output is correct |
37 |
Correct |
8 ms |
840 KB |
Output is correct |
38 |
Correct |
9 ms |
840 KB |
Output is correct |
39 |
Correct |
42 ms |
876 KB |
Output is correct |
40 |
Correct |
8 ms |
748 KB |
Output is correct |
41 |
Correct |
1 ms |
364 KB |
Output is correct |
42 |
Correct |
9 ms |
876 KB |
Output is correct |
43 |
Correct |
383 ms |
876 KB |
Output is correct |
44 |
Correct |
392 ms |
1004 KB |
Output is correct |
45 |
Correct |
399 ms |
1004 KB |
Output is correct |
46 |
Correct |
384 ms |
1004 KB |
Output is correct |
47 |
Correct |
402 ms |
1004 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 |
364 KB |
Output is correct |
52 |
Correct |
1 ms |
512 KB |
Output is correct |
53 |
Correct |
1 ms |
364 KB |
Output is correct |
54 |
Correct |
387 ms |
1004 KB |
Output is correct |
55 |
Correct |
389 ms |
1004 KB |
Output is correct |
56 |
Correct |
394 ms |
1004 KB |
Output is correct |
57 |
Correct |
410 ms |
1132 KB |
Output is correct |
58 |
Correct |
397 ms |
1004 KB |
Output is correct |
59 |
Correct |
9 ms |
876 KB |
Output is correct |
60 |
Correct |
6 ms |
1004 KB |
Output is correct |
61 |
Correct |
6 ms |
1004 KB |
Output is correct |
62 |
Correct |
48 ms |
1004 KB |
Output is correct |
63 |
Correct |
9 ms |
876 KB |
Output is correct |
64 |
Correct |
43 ms |
1004 KB |
Output is correct |
65 |
Correct |
9 ms |
876 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
364 KB |
Output is correct |
2 |
Correct |
1 ms |
364 KB |
Output is correct |
3 |
Correct |
1 ms |
364 KB |
Output is correct |
4 |
Correct |
1 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 |
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 |
1 ms |
364 KB |
Output is correct |
15 |
Correct |
1 ms |
364 KB |
Output is correct |
16 |
Correct |
157 ms |
8812 KB |
Output is correct |
17 |
Correct |
152 ms |
8812 KB |
Output is correct |
18 |
Correct |
157 ms |
8836 KB |
Output is correct |
19 |
Correct |
150 ms |
8812 KB |
Output is correct |
20 |
Correct |
165 ms |
8812 KB |
Output is correct |
21 |
Correct |
159 ms |
8812 KB |
Output is correct |
22 |
Correct |
154 ms |
8812 KB |
Output is correct |
23 |
Correct |
148 ms |
8748 KB |
Output is correct |
24 |
Correct |
153 ms |
8812 KB |
Output is correct |
25 |
Correct |
152 ms |
8812 KB |
Output is correct |
26 |
Correct |
159 ms |
8808 KB |
Output is correct |
27 |
Correct |
160 ms |
8756 KB |
Output is correct |
28 |
Correct |
144 ms |
8812 KB |
Output is correct |
29 |
Correct |
168 ms |
8812 KB |
Output is correct |
30 |
Correct |
171 ms |
8960 KB |
Output is correct |
31 |
Correct |
149 ms |
8812 KB |
Output is correct |
32 |
Correct |
152 ms |
8812 KB |
Output is correct |
33 |
Correct |
170 ms |
8812 KB |
Output is correct |
34 |
Correct |
143 ms |
8812 KB |
Output is correct |
35 |
Correct |
147 ms |
8812 KB |
Output is correct |
36 |
Correct |
1 ms |
364 KB |
Output is correct |
37 |
Correct |
38 ms |
840 KB |
Output is correct |
38 |
Correct |
44 ms |
840 KB |
Output is correct |
39 |
Correct |
42 ms |
748 KB |
Output is correct |
40 |
Correct |
39 ms |
888 KB |
Output is correct |
41 |
Correct |
344 ms |
840 KB |
Output is correct |
42 |
Correct |
347 ms |
840 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 |
245 ms |
868 KB |
Output is correct |
50 |
Correct |
230 ms |
840 KB |
Output is correct |
51 |
Correct |
213 ms |
840 KB |
Output is correct |
52 |
Correct |
178 ms |
868 KB |
Output is correct |
53 |
Correct |
147 ms |
840 KB |
Output is correct |
54 |
Correct |
39 ms |
876 KB |
Output is correct |
55 |
Correct |
5 ms |
896 KB |
Output is correct |
56 |
Correct |
5 ms |
876 KB |
Output is correct |
57 |
Correct |
8 ms |
840 KB |
Output is correct |
58 |
Correct |
9 ms |
840 KB |
Output is correct |
59 |
Correct |
42 ms |
876 KB |
Output is correct |
60 |
Correct |
8 ms |
748 KB |
Output is correct |
61 |
Correct |
1 ms |
364 KB |
Output is correct |
62 |
Correct |
753 ms |
12912 KB |
Output is correct |
63 |
Correct |
1164 ms |
12556 KB |
Output is correct |
64 |
Correct |
1167 ms |
12268 KB |
Output is correct |
65 |
Correct |
1164 ms |
12268 KB |
Output is correct |
66 |
Execution timed out |
3058 ms |
12744 KB |
Time limit exceeded |
67 |
Halted |
0 ms |
0 KB |
- |