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>
#define SPEED ios_base::sync_with_stdio(false);cin.tie(NULL);
// #pragma GCC optimize("Ofast,no-stack-protector,unroll-loops")
// #pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
using namespace std;
typedef long long int lli;
typedef vector<int> vi;
typedef vector<long long int> vll;
const int mod = 1000000007;
int main(){
SPEED;
int N; cin >> N;
vll arr(N+2), pref(N+2), dp(N+2);
vi best(N+2);
for( int i = 1; i <= N; i++ ){
cin >> arr[i];
pref[i] = pref[i-1] + arr[i];
}
for( int i = 1; i <= N; i++ ){
best[i] = max( best[i], best[i-1] );
dp[i] = 1 + dp[best[i]];
lli currSum = 2 * pref[i] - pref[best[i]];
int next = lower_bound(pref.begin() + 1, pref.begin() + N + 1, currSum ) - pref.begin();
best[next] = max( best[next], i );
}
cout << dp[N] << 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... |