제출 #1082246

#제출 시각아이디문제언어결과실행 시간메모리
1082246ByeWorldBigger segments (IZhO19_segments)C++14
37 / 100
1543 ms3700 KiB
#include <bits/stdc++.h>
#pragma GCC optimize("O3")
#define int long long
#define ll long long
#define pb push_back
#define fi first
#define se second
#define lf (id<<1)
#define rg ((id<<1)|1)
#define md ((l+r)>>1)
using namespace std;
typedef pair<int,int> pii;
typedef pair<int,pii> ipii;
const int MAXN = 5e5+15;
const int INF = 1e9+10;
const int MOD = 1e9+7;

/*
dp[i] : max segment [1..i]
pref[i] : prefix sum [1..i]
opt[i] : min last segment untuk mendapatkan dp[i]

for (int i=1;i<=N;i++) {
    for (int j=i-1;j>=0;j--) {
        if (opt[j] <= pref[i]-pref[j]) {
            dp[i] = dp[j]+1;
            opt[i] = pref[i]-pref[j];
            break;
        }
    }
}
*/
int n;
int a[MAXN], dp[MAXN], pr[MAXN], opt[MAXN];

signed main(){
    cin >> n;
    for(int i=1; i<=n; i++){ cin >> a[i]; pr[i] = pr[i-1]+a[i]; }
    for(int i=1; i<=n; i++){
        for(int j=i-1; j>=0; j--){
            if(opt[j] <= pr[i]-pr[j]){
                dp[i] = dp[j]+1;
                opt[i] = pr[i]-pr[j];
                break;
            }
        }
    }
    cout << dp[n] << '\n';
}
#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...