#include <bits/stdc++.h>
//#include "grader.h"
/*#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>*/
#define ll long long
#define ll1 long long
#define ull unsigned long long
#define dou long double
#define str string
#define vll vector<ll>
#define vi vector<int>
#define pll pair<ll, ll>
#define vpll vector<pll>
#define vbool vector<bool>
#define vstr vector<str>
#define vvll vector<vll>
#define pb push_back
#define pf push_front
//#define endl "\n"
#define fr first
#define se second
// #define sortcmp(a) sort(a.begin(), a.end(), cmp)
#define sort(a) sort(a.begin(), a.end())
#define all(a) a.begin(), a.end()
#define reverse(a) reverse(a.begin(), a.end())
#define speed ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define INF 1000000000000000000
#define ordered_set tree<pll, null_type, less<pll>, rb_tree_tag, tree_order_statistics_node_update>
using namespace std;
//using namespace __gnu_pbds;
mt19937 rng(1488);
ll randll(ll l, ll r){
return uniform_int_distribution<ll>(l, r)(rng);
}
int main() {
srand(time(0));
speed;
ll n;
cin >> n;
vll a(n);
for (int i =0 ; i < n; i ++) {
cin >> a[i];
}
ll k = 1, sm = 0, s = a[0], sp = 0, l1 = 1;
ll l = 1;
for (int i = 1; i < n; i ++) {
sm += a[i];
if (k > 1) {
if (sm*2 < a[l] && s+sm >= sp+a[l]) {
s += sm;
sp += a[l];
s -= a[l];
l ++;
l1 = i+1;
sm = 0;
}
}
//cout << sm << ' ' << s << endl;
if (sm >= s) {
k ++;
sp = s;
s = sm;
sm = 0;
l = l1;
l1 = i+1;
while (1) {
if (sp+a[l] <= s - a[l]) {
sp += a[l];
s -= a[l];
l ++;
}
else break;
}
}
}
cout << k << endl;
}
# | 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... |