# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
676275 | Toxtaq | Bigger segments (IZhO19_segments) | C++17 | 312 ms | 284 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>
using namespace std;
int check(int mid, vector<int>&v, vector<int>&suff){
int temp = 0, prev = -1, indx = 0, result = 0;
while(temp <= mid)temp += v[indx++];
prev = temp;
temp = 0;
if(prev < mid)return 0;
result++;
for(int i = indx;i < v.size();++i){
temp += v[i];
if(prev <= temp){
if(i != v.size() - 1 && suff[i + 1] < temp){
return result + 1;
}
else{
result++;
prev = temp;
temp = 0;
}
}
}
return result;
}
int main()
{
int n;
cin >> n;
vector<int>v(n), suff(n);
for(int i = 0;i < n;++i)cin >> v[i];
suff[n - 1] = v[n - 1];
for(int i = n - 2;i >= 0;--i)suff[i] = suff[i + 1] + v[i];
int l = 1, r = 1e9, Mx = 0;
for(int i = 1;i < suff[0];++i){
Mx = max(Mx, check(i, v, suff));
// cout << "i=" << i << ": " << Mx << '\n';
}
cout << Mx;
}
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... |