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 <algorithm>
#include <iostream>
#include <vector>
#include <iterator>
using namespace std;
typedef long long ll;
const int N = 500005;
ll arr[N], pref[N];
int main()
{
ll i, n;
cin >> n;
for (i = 0; i < n; i++)
cin >> arr[i];
vector<ll>v;
vector<ll>::iterator it;
ll p = arr[0];
ll k = 0;
ll res = 1;
for (i = 1; i < n; i++)
{
k += arr[i];
v.push_back(k);
if (k >= p)
{
res++;
it = lower_bound(v.begin(), v.end(), (k - p) / 2);
if (it == v.begin())
{
p = k;
k = 0;
v.erase(v.begin(), v.end());
}
else
{
ll e = distance(v.begin(), it);
p = k - v[e - 1];
k = 0;
v.erase(v.begin(), v.end());
}
}
}
cout << res << endl;
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... |