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;
#define ll long long
#define pb push_back
#define fi first
#define se second
const int mod=1e9+7, maxn=5e5+5;
ll n, a[maxn], ans, sum;
pair<ll, ll> last;
int main() {
ios_base::sync_with_stdio(false); cin.tie(NULL);
cin >> n;
for(int i=1; i<=n; i++) cin >> a[i];
last={a[1], 1};
ans=1;
for(int i=2; i<=n; i++) {
sum+=a[i];
if(sum>=last.fi) {
while(true) {
if(last.fi+a[last.se+1]<=sum-a[last.se+1]) {
last.fi+=a[last.se+1];
sum-=a[last.se+1];
last.se++;
} else break;
}
ans++;
last={sum, i};
sum=0;
}
}
cout << ans << '\n';
}
# | 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... |