# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
384305 | vanic | Bigger segments (IZhO19_segments) | C++14 | 1 ms | 364 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 <iostream>
#include <cmath>
#include <algorithm>
#include <vector>
using namespace std;
typedef long long ll;
const int maxn=5e5+5;
vector < int > ind;
vector < ll > val;
ll a[maxn];
void siftaj(int x){
if(x==val.size()-1 || x==-1){
return;
}
bool jes=0;
while(val[x]+a[ind[x]]<=val[x+1]-a[ind[x]]){
jes=1;
val[x]+=a[ind[x]];
val[x+1]-=a[ind[x]];
ind[x]++;
}
if(jes){
siftaj(x-1);
siftaj(x+1);
}
}
int main(){
ios_base::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
int n;
cin >> n;
for(int i=0; i<n; i++){
cin >> a[i];
}
ind.push_back(1);
val.push_back(a[0]);
ll sad=0;
for(int i=1; i<n; i++){
sad+=a[i];
if(val.back()<=sad){
val.push_back(sad);
ind.push_back(i+1);
siftaj(val.size()-2);
sad=0;
}
}
cout << val.size() << '\n';
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... |