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 pb push_back
#define mp make_pair
#define ff first
#define ss second
const int N = 5*1e5+11;
int n;
ll a[N], ak[N], b[N], z[N];
bool prov (int zad, int pos) {
ll sada = ak[pos];
if (zad > 0) sada -= ak[zad-1];
ll curr = 0;
if (zad > 0) curr += b[zad-1];
if (sada >= curr) return 1;
return 0;
}
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cin >> n;
for (int i=0;i<n;i++) {
cin >> a[i];
ak[i] = a[i];
if (i > 0) ak[i] += ak[i-1];
}
for (int i=0;i<n;i++) {
int lo = 0, hi = i;
while (lo < hi) {
int mid = (lo+hi)/2;
if (prov(mid, i)) lo = mid+1;
else hi = mid;
}
if (!prov(lo, i)) lo--;
b[i] = ak[i];
if (lo > 0) b[i] -= ak[lo-1];
z[i] = lo-1;
}
int br = 0;
int x = n-1;
while (x >= 0) {
br++;
x = z[x];
}
cout << br;
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... |