# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
898598 | White | Bigger segments (IZhO19_segments) | C++14 | 1 ms | 348 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#pragma GCC optimize <"O3">
#include <bits/stdc++.h>
#define endl "\n"
using namespace std;
long long red[500005];
vector<long long>clr,cur;
long long binary(long long now){
long long l=0,r=cur.size()-1,mid,kr=cur.size()-1;
if(cur.empty())return -1;
while(l<r){
mid=(l+r)/2;
if(cur[kr]-cur[mid]>=now)l=mid+1;
else r=mid;
}
if(cur[kr]<now)return -1;
if(cur[kr]-cur[l]<now)l--;
if(l==-1)return -2;
return l;
}
long long binary2(long long L,long long N){
long long l=0,r=cur.size(),mid,kr=cur.size()-1;
for(;l<cur.size();l++){
if(cur[kr]-cur[l]+N<L+cur[l])break;
}
l--;
return l;
}
int main(){
//ios_base::sync_with_stdio(false);
//cin.tie(NULL);
long long n;
cin>>n;
for(int i=0;i<n;i++)cin>>red[i];
long long br=1,L=red[0],otg=0;
for(int i=1;i<n;i++){
//cout<<"L: "<<L<<endl;
long long N=red[i];
if(N>=L){
br++;
if(cur.size()>0){
long long kude=binary2(L,N);
//cout<<kude<<endl;
if(kude>-1)L=N+cur[cur.size()-1]-cur[kude];
else L=N+cur[cur.size()-1];
while(cur.empty()==false)cur.pop_back();
}else{
L=N;
}
}else{
long long kude=binary(L-N);
//cout<<kude<<endl;
if(kude==-1){
if(cur.empty()==true)cur.push_back(N);
else cur.push_back(cur[cur.size()-1]+N);
}else{
br++;
if(kude>=0)L=N+cur[cur.size()-1]-cur[kude];
else L=N+cur[cur.size()-1];
while(cur.empty()==false)cur.pop_back();
}
}
}
otg=max(otg,br);
br=1;L=red[0]+red[1];
for(int i=2;i<n;i++){
//cout<<"L: "<<L<<endl;
long long N=red[i];
if(N>=L){
br++;
if(cur.size()>0){
long long kude=binary2(L,N);
//cout<<kude<<endl;
if(kude>-1)L=N+cur[cur.size()-1]-cur[kude];
else L=N+cur[cur.size()-1];
while(cur.empty()==false)cur.pop_back();
}else{
L=N;
}
}else{
long long kude=binary(L-N);
//cout<<kude<<endl;
if(kude==-1){
if(cur.empty()==true)cur.push_back(N);
else cur.push_back(cur[cur.size()-1]+N);
}else{
br++;
if(kude>=0)L=N+cur[cur.size()-1]-cur[kude];
else L=N+cur[cur.size()-1];
while(cur.empty()==false)cur.pop_back();
}
}
}
otg=max(otg,br);
cout<<otg<<endl;
return 0;
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |