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;
typedef long long ll;
#define int ll
signed main() {
int n;
cin>>n;
vector<int>a(n);
for(int i=0;i<n;i++){
cin>>a[i];
}
int ind=0;
ll p_sum=0;
int ans=0;
while(ind<n){
ll sum=0;
ll best_sum=1e18;
int best_ind=-1;
ll best_choice=0;
for(int i=ind;i<n;i++){
sum+=a[i];
if(sum<p_sum)continue;
ll cur=0;
for(int j=i+1;j<n;j++){
cur+=a[j];
if(cur>=sum){
if(cur<best_sum){
best_sum=cur;
best_ind=i;
best_choice=sum;
}
}
}
}
ans++;
if(best_ind==-1)break;
p_sum=best_choice;
ind=best_ind+1;
}
cout<<ans;
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... |