제출 #1166387

#제출 시각아이디문제언어결과실행 시간메모리
1166387DangKhoizzzzBigger segments (IZhO19_segments)C++20
37 / 100
6 ms1864 KiB
// checkk if small sub full

#include <bits/stdc++.h>
#define int long long
#define fi first
#define se second
#define pii pair <int , int>
#define arr3 array <int , 3>

/*
+ array limit ???
+ special case ??? n = 1?
+ time limit ???
*/

using namespace std;

const int INF = 1e18 + 7;
const int maxn = 2e5 + 7;


int n , a[maxn] , pre[maxn];
pii dp[maxn];


namespace small_subtask
{
    int ans = 0;

    void solve()
    {
        for(int i = 1; i <= n; i++)
        {
            for(int j = 0; j <= i-1; j++)
            {
                if((pre[i] - pre[j]) >= dp[j].se)
                {
                    if(dp[i].fi < dp[j].fi + 1)
                    {
                        dp[i].fi = dp[j].fi + 1;
                        dp[i].se = pre[i] - pre[j];
                    }
                    else if(dp[i].fi == dp[j].fi + 1)
                    {
                        dp[i].se = min(dp[i].se , pre[i] - pre[j]);
                    }
                }
            }

            ans = max(ans , dp[i].fi);
        }
        cout << ans << '\n';
    }
}

namespace full_subtask
{
    void solve()
    {

    }
}



void read_solve()
{
    cin >> n;
    for(int i = 1; i <= n; i++) cin >> a[i];
    for(int i = 1; i <= n; i++)
    {
        pre[i] = pre[i-1] + a[i];
    }
    if(n <= 3000) small_subtask::solve();
    else full_subtask::solve();
}


signed main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0); cout.tie(0);
    //freopen("inp.txt" , "r" , stdin);
    //freopen("out.txt" , "w" , stdout);
    read_solve();
    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...