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;
#define int long long
signed main()
{
int n; cin >> n;
vector<int> a(n + 1), pref(n + 1);
for (int i = 1; i<= n; i++){
cin >> a[i];
pref[i] = pref[i - 1] + a[i];
}
vector<pair<int, int>> dp(n + 1);
dp[1] = {1, a[1]};
for (int i = 2; i <= n; i++){
int ini = 1, fin = i;
while(ini < fin){
int m = (ini + fin) / 2;
if (dp[m].second <= pref[i]- pref[m]){
ini = m + 1;
}else fin = m;
}
ini--;
int sum = pref[i] - pref[ini];
dp[i] = {dp[ini].first + 1, sum};
}
cout << dp[n].first << 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... |