이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#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==(int)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;
}
}
while(ind.back()<n-1 && sad<val.back()){
ind[ind.size()-1]++;
siftaj(val.size()-2);
}
if(sad>=val.back()){
val.push_back(sad);
}
cout << val.size() << '\n';
return 0;
}
# | 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... |