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 <iostream>
#include <iomanip>
#include <fstream>
#include <algorithm>
#include <cstring>
#include <string>
#include <vector>
#include <queue>
#include <deque>
#include <stack>
#include <cmath>
#include <list>
#include <set>
#include <map>
using namespace std;
#define all(a) a.begin(), a.end()
typedef long long ll;
const ll N = 2000004;
const ll mod = 1000 * 1000 * 1000 + 7;
const ll inf = 1000000000;
ll n, m, k, z, t, x, y, a[N],ans[N],idx[N];
int main()
{
cin >> n;
for (int i = 1; i <= n; ++i)
{
cin >> a[i];
a[i] += a[i - 1];
}
for (int i = 1; i <= n; ++i)
{
idx[i] = max(idx[i], idx[i - 1]);
ans[i] = ans[idx[i]] + 1;
int id = lower_bound(a + 1, a + n + 1, 2 * a[i] - a[idx[i]]) - a;
if (id <= n)
idx[id] = max(idx[id],ll(i));
}
cout << ans[n];
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... |