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>
#define fi first
#define se second
#define ll long long
#define dl double long
using namespace std;
const int N = 3e5 + 7;
const long long mod = 1e9 + 7;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
int main()
{
ios_base::sync_with_stdio(0);
//freopen( "input.txt" , "r" , stdin );
//freopen( "output.txt" , "w" , stdout );
int n;
cin >> n;
vector < int > a( n + 1 , 0 );
for( int i = 1; i <= n; i++ ){
cin >> a[i];
}
int ans = 1;
ll ns = 0;
ll ps = a[1];
int ls = 2;
for( int i = 2; i <= n; i++ ){
if( ps <= ns ){
while( ns - 2 * a[ls] >= ps ){
ns -= a[ls];
ps += a[ls];
ls++;
}
ps = ns;
ls = i;
ans++;
ns = 0;
i--;
}else{
ns += a[i];
}
}
cout << ans + (ns >= ps);
}
# | 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... |