#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define endl '\n'
#define INF 1e9+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__)
const int mxn=3e5+10;
int n,d;
map<int,vector<int>> ar;
struct dt {
int x,a,b;
bool operator<(const dt &r) {return x<r.x;}
};
vector<dt> s;
vector<int> B;
int t[3*mxn],lazy[3*mxn];
ll sum[mxn];
ll ans=INF;
void push(int x) {
t[2*x]+=lazy[x];
t[2*x+1]+=lazy[x];
lazy[2*x]+=lazy[x];
lazy[2*x+1]+=lazy[x];
lazy[x]=0;
}
void build(int v,int tl,int tr) {
if(tl==tr) {
t[v]=-s[tl].x;
if(tl) t[v]+=sum[tl-1];
}
else {
int mid=(tl+tr)/2;
build(2*v,tl,mid);
build(2*v+1,mid+1,tr);
t[v]=min(t[2*v],t[2*v+1]);
}
}
void add(int v,int tl,int tr,int l,int r,int val) {
if(tl>tr or tl>r or tr<l) return;
if(tl>=l and tr<=r) {
t[v]+=val;
lazy[v]+=val;
}
else {
push(v);
int mid=(tl+tr)/2;
add(2*v,tl,mid,l,r,val);
add(2*v+1,mid+1,tr,l,r,val);
t[v]=min(t[2*v],t[2*v+1]);
}
}
int query(int v,int tl,int tr,int l,int r) {
if(l>r or l>tr or r<tl) return INF;
if(tl>=l and tr<=r) {
return t[v];
}
else {
push(v);
int mid=(tl+tr)/2;
return min(query(2*v,tl,mid,l,r),query(2*v+1,mid+1,tr,l,r));
}
}
int main () {
ios::sync_with_stdio(false); cin.tie(0);
cin>>n>>d; int N=n+1;
for(int i=0;i<n;i++) {
int x,a,b; cin>>x>>a>>b;
s.push_back({x,a,b}); B.push_back(b);
}
s.push_back({d,0,d}); B.push_back(d);
sort(all(s));
sort(all(B)); B.erase(unique(all(B)),end(B));
for(int i=0;i<N;i++) {
sum[i]=s[i].a;
if(i) sum[i]+=sum[i-1];
}
for(int i=0;i<N;i++) {
ar[s[i].b].push_back(i);
}
build(1,0,N-1);
int past=-1;
for(auto e:B) {
if(past==-1) add(1,0,N-1,0,N-1,e);
else add(1,0,N-1,0,N-1,e-past);
int res=query(1,0,N-1,0,N-1);
//debug(res);
if(res>=0) {
cout<<e-res<<endl; return 0;
}
for(int u:ar[e]) {
add(1,0,N-1,u+1,N-1,-s[u].a);
}
past=e;
}
}
# |
Verdict |
Execution time |
Memory |
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 |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
174 ms |
30232 KB |
Execution killed with signal 11 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
492 KB |
Output is correct |
2 |
Correct |
6 ms |
1004 KB |
Output is correct |
3 |
Correct |
6 ms |
1132 KB |
Output is correct |
4 |
Correct |
6 ms |
1012 KB |
Output is correct |
5 |
Correct |
6 ms |
1012 KB |
Output is correct |
6 |
Correct |
9 ms |
1900 KB |
Output is correct |
7 |
Correct |
8 ms |
1900 KB |
Output is correct |
8 |
Correct |
1 ms |
364 KB |
Output is correct |
9 |
Correct |
1 ms |
500 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 |
11 ms |
1644 KB |
Output is correct |
15 |
Correct |
11 ms |
1644 KB |
Output is correct |
16 |
Correct |
11 ms |
1644 KB |
Output is correct |
17 |
Correct |
11 ms |
1516 KB |
Output is correct |
18 |
Correct |
11 ms |
1388 KB |
Output is correct |
19 |
Correct |
6 ms |
1132 KB |
Output is correct |
20 |
Correct |
5 ms |
1012 KB |
Output is correct |
21 |
Correct |
5 ms |
1012 KB |
Output is correct |
22 |
Correct |
5 ms |
1024 KB |
Output is correct |
23 |
Correct |
5 ms |
1004 KB |
Output is correct |
24 |
Correct |
7 ms |
1132 KB |
Output is correct |
25 |
Correct |
5 ms |
1004 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
492 KB |
Output is correct |
2 |
Correct |
6 ms |
1004 KB |
Output is correct |
3 |
Correct |
6 ms |
1132 KB |
Output is correct |
4 |
Correct |
6 ms |
1012 KB |
Output is correct |
5 |
Correct |
6 ms |
1012 KB |
Output is correct |
6 |
Correct |
9 ms |
1900 KB |
Output is correct |
7 |
Correct |
8 ms |
1900 KB |
Output is correct |
8 |
Correct |
1 ms |
364 KB |
Output is correct |
9 |
Correct |
1 ms |
500 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 |
11 ms |
1644 KB |
Output is correct |
15 |
Correct |
11 ms |
1644 KB |
Output is correct |
16 |
Correct |
11 ms |
1644 KB |
Output is correct |
17 |
Correct |
11 ms |
1516 KB |
Output is correct |
18 |
Correct |
11 ms |
1388 KB |
Output is correct |
19 |
Correct |
6 ms |
1132 KB |
Output is correct |
20 |
Correct |
5 ms |
1012 KB |
Output is correct |
21 |
Correct |
5 ms |
1012 KB |
Output is correct |
22 |
Correct |
5 ms |
1024 KB |
Output is correct |
23 |
Correct |
5 ms |
1004 KB |
Output is correct |
24 |
Correct |
7 ms |
1132 KB |
Output is correct |
25 |
Correct |
5 ms |
1004 KB |
Output is correct |
26 |
Correct |
1 ms |
384 KB |
Output is correct |
27 |
Runtime error |
172 ms |
28936 KB |
Execution killed with signal 11 |
28 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
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 |
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 |
384 KB |
Output is correct |
24 |
Correct |
1 ms |
364 KB |
Output is correct |
25 |
Incorrect |
1 ms |
364 KB |
Output isn't correct |
26 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
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 |
492 KB |
Output is correct |
17 |
Correct |
6 ms |
1004 KB |
Output is correct |
18 |
Correct |
6 ms |
1132 KB |
Output is correct |
19 |
Correct |
6 ms |
1012 KB |
Output is correct |
20 |
Correct |
6 ms |
1012 KB |
Output is correct |
21 |
Correct |
9 ms |
1900 KB |
Output is correct |
22 |
Correct |
8 ms |
1900 KB |
Output is correct |
23 |
Correct |
1 ms |
364 KB |
Output is correct |
24 |
Correct |
1 ms |
500 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 |
11 ms |
1644 KB |
Output is correct |
30 |
Correct |
11 ms |
1644 KB |
Output is correct |
31 |
Correct |
11 ms |
1644 KB |
Output is correct |
32 |
Correct |
11 ms |
1516 KB |
Output is correct |
33 |
Correct |
11 ms |
1388 KB |
Output is correct |
34 |
Correct |
6 ms |
1132 KB |
Output is correct |
35 |
Correct |
5 ms |
1012 KB |
Output is correct |
36 |
Correct |
5 ms |
1012 KB |
Output is correct |
37 |
Correct |
5 ms |
1024 KB |
Output is correct |
38 |
Correct |
5 ms |
1004 KB |
Output is correct |
39 |
Correct |
7 ms |
1132 KB |
Output is correct |
40 |
Correct |
5 ms |
1004 KB |
Output is correct |
41 |
Correct |
1 ms |
364 KB |
Output is correct |
42 |
Correct |
10 ms |
1260 KB |
Output is correct |
43 |
Correct |
14 ms |
2164 KB |
Output is correct |
44 |
Incorrect |
13 ms |
2304 KB |
Output isn't correct |
45 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
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 |
Runtime error |
174 ms |
30232 KB |
Execution killed with signal 11 |
17 |
Halted |
0 ms |
0 KB |
- |