제출 #241713

#제출 시각아이디문제언어결과실행 시간메모리
241713valerikkBigger segments (IZhO19_segments)C++17
37 / 100
1582 ms3440 KiB
#include<bits/stdc++.h>
using namespace std;

#define mp make_pair
#define pb push_back
#define x first
#define y second
#define all(a) (a).begin(), (a).end()
typedef long long ll;

template<class A, class B> bool mmin(A& a, B b) {if (b < a) {a = b; return 1;} return 0;}
template<class A, class B> bool mmax(A& a, B b) {if (b > a) {a = b; return 1;} return 0;}

pair<int, ll> merg(pair<int, ll> a, pair<int, ll> b) {
    if (a.x > b.x || (a.x == b.x && a.y < b.y)) return a;
    return b;
}

ll a[100005], sum[100005];
pair<int, ll> dp[100005];

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n;
    cin >> n;
    for (int i = 0; i < n; i++) {
        cin >> a[i];
        sum[i + 1] = sum[i] + a[i];
    }
    dp[0] = mp(0, 0);
    for (int i = 1; i <= n; i++) {
        dp[i] = mp(0, 0);
        for (int j = 0; j < i; j++) {
            if (dp[j].y <= sum[i] - sum[j]) {
                pair<int, ll> now = mp(dp[j].x + 1, sum[i] - sum[j]);
                dp[i] = merg(dp[i], now);
            }
        }
    }
    cout << dp[n].x;
    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...