Submission #1122887

#TimeUsernameProblemLanguageResultExecution timeMemory
1122887Ice_manBigger segments (IZhO19_segments)C++17
100 / 100
72 ms12104 KiB
/**
 ____    ____    ____    __________________    ____    ____    ____
||I ||  ||c ||  ||e ||  ||                ||  ||M ||  ||a ||  ||n ||
||__||  ||__||  ||__||  ||________________||  ||__||  ||__||  ||__||
|/__\|  |/__\|  |/__\|  |/________________\|  |/__\|  |/__\|  |/__\|

*/

#include <iostream>
#include <chrono>
#include <vector>
#include <algorithm>

#define maxn 500005
#define maxlog 20
#define INF 1000000010
#define LINF 1000000000000000005
#define endl '\n'
#define pb(x) push_back(x)
#define X first
#define Y second
#define control cout<<"passed"<<endl;

using namespace std;


typedef pair <int, int> pii;
typedef long long ll;
typedef pair <ll, ll> pll;
typedef pair <int, ll> pil;
typedef pair <ll, int> pli;
typedef long double ld;





ll pref[maxn];
int a[maxn] , n;
int endd[maxn];
ll dp[maxn];

void read()
{
    cin >> n;

    for(int i = 1; i <= n; i++)
        cin >> a[i];
    for(int i = 1; i <= n; i++)
        pref[i] = pref[i - 1] + a[i];


    for(int i = 1; i <= n; i++)
    {
        endd[i] = max(endd[i] , endd[i - 1]);
        dp[i] = dp[endd[i]] + 1;
        int pos = lower_bound(pref , pref + 1 + n , -pref[endd[i]] + 2 * pref[i]) - pref;

        endd[pos] = i;
    }

    cout << dp[n] << endl;
}











int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);

    read();


    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...