Submission #467301

#TimeUsernameProblemLanguageResultExecution timeMemory
467301theconfusedguyBigger segments (IZhO19_segments)C++14
100 / 100
118 ms18876 KiB
#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 timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...