# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
441543 | leaked | Bigger segments (IZhO19_segments) | C++14 | 1 ms | 312 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.
#include <bits/stdc++.h>
#define vec vector
using namespace std;
typedef long long ll;
signed main(){
ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
int n;
cin>>n;
vec<int>a(n);
vec<ll>pref(n);
for(auto &z : a) cin>>z;
for(int i=0;i<n;i++){
pref[i]=(i?pref[i-1]:0)+a[i];
}
auto get=[&](int l,int r){
return pref[r]-pref[l-1];
};
ll lst=a[0],s=0;
int cnt=1;
int w=0;
for(int i=1;i<n;i++){
s+=a[i];
if(s>=lst){
int j=w;
while(1){
if(pref[i]-pref[j]<pref[j]-pref[w]+lst) break;
j++;
}
j--;
cnt++;
lst=pref[i]-pref[j];
w=i;
s=0;
}
}
cout<<cnt;
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... |