제출 #344615

#제출 시각아이디문제언어결과실행 시간메모리
344615tata666Bigger segments (IZhO19_segments)C++17
27 / 100
1572 ms2976 KiB
#include <bits/stdc++.h>

#define pb push_back
#define F first
#define S second

using namespace std;

typedef long long llong;

const int MOD = 1e9 + 7;
const int MXN = 4e5 + 7;
const llong INF = 1e18 + 7;

int n, ans;
int dp[3001][3001];
llong pref[MXN], a[MXN];

int main(){
  ios_base::sync_with_stdio(0);
  //freopen("input.txt", "r", stdin);
  //freopen("output.txt", "w", stdout);
  cin >> n;
  for(int i = 1; i <= n; i++){
    cin >> a[i];
    dp[1][i] = 1;
    pref[i] = pref[i - 1] + a[i];
  }
  for(int i = 1; i <= n; i++){
    for(int j = i; j <= n; j++){
      for(int k = j + 1; k <= n; k++){
        if(i > 1 && !dp[i][j]) continue;
        if(pref[j] - pref[i - 1] <= pref[k] - pref[j]){
          dp[j + 1][k] = max(dp[j + 1][k], dp[i][j] + 1);
        }
      }
    }
  }
  /*for(int i = 1; i <= n; i++){
    for(int j = i; j <= n; j++){
      cout << i << ' ' << j << " : " << dp[i][j] << endl;
    }
  }*/
  for(int i = 1; i <= n; i++){
    ans = max(dp[i][n], ans);
  }
  cout << ans;
  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...