#include <bits/stdc++.h>
using namespace std;
#define fr first
#define sc second
const int mxn=1e5+5,sz=(1<<20);
int n,vmx,v2,t[mxn],a[mxn];
vector<pair<int,int>>v;
struct segment{
int mx[sz],mn[sz],lazy[sz];
void shift(int id){
for(int i=0;i<2;i++){
mx[id*2+i]+=lazy[id];
mn[id*2+i]+=lazy[id];
lazy[id*2+i]+=lazy[id];
}
lazy[id]=0;
}
void add(int id,int L,int R,int l,int r,int x){
if(L==l && R==r){
lazy[id]+=x;
mx[id]+=x;
mn[id]+=x;
return ;
}
if(lazy[id])
shift(id);
int mid=(L+R)/2;
if(l<mid)
add(id*2,L,mid,l,min(r,mid),x);
if(r>mid)
add(id*2+1,mid,R,max(l,mid),r,x);
mx[id]=max(mx[id*2],mx[id*2+1]);
mn[id]=min(mn[id*2],mn[id*2+1]);
}
}seg;
int main(){
cin>>n>>vmx>>v2;
for(int i=1;i<=n;i++){
char x;
cin>>x>>t[i];
if(x=='+')a[i]=1;
else a[i]=-1;
if(i!=1)seg.add(1,1,n+2,1,i+1,-a[i]);
}
seg.add(1,1,n+2,1,n+2,v2);
for(int i=n;i>1;i--){
t[i]-=t[i-1];
v.push_back({t[i],i});
}
v.push_back({0,0});
sort(v.begin(),v.end());
int p=v.back().fr;
while(v.size()){//cout<<seg.mx[1]<<" "<<seg.mn[1]<<endl;
if(seg.mx[1]<=vmx && seg.mn[1]>=0)break;
while(v.back().fr==p){
seg.add(1,1,n+2,1,v.back().sc+1,a[v.back().sc]);
v.pop_back();
}
p=v.back().fr;
}
cout<<v.back().fr<<" ";
int l=0,r=vmx+1,y=v.back().fr;
while(r-l>1){
int mid=(l+r)/2,x=mid;
for(int i=2;i<=n;i++){
if(y>=t[i]){
x+=a[i];
x=max(0,x);
x=min(x,vmx);
}
}
if(x<=v2)l=mid;
else r=mid;
}
cout<<l;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
4444 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
4640 KB |
Output is correct |
2 |
Correct |
3 ms |
4700 KB |
Output is correct |
3 |
Incorrect |
3 ms |
4736 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
4440 KB |
Output is correct |
2 |
Incorrect |
2 ms |
4444 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
3 ms |
4696 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
18 ms |
9952 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
21 ms |
9804 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
28 ms |
9820 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
39 ms |
10712 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
82 ms |
12744 KB |
Output is correct |
2 |
Correct |
73 ms |
12744 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
83 ms |
12728 KB |
Output is correct |
2 |
Correct |
72 ms |
12748 KB |
Output is correct |