Submission #344657

#TimeUsernameProblemLanguageResultExecution timeMemory
344657tata666Bigger segments (IZhO19_segments)C++17
13 / 100
642 ms262148 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, dp[3001][3001], ans;
queue <pair <int, int> > q;
llong a[MXN], pref[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];
    pref[i] = pref[i - 1] + a[i];
    dp[1][i] = 1;
    q.push({1, i});
  }
  while(!q.empty()){
    int l = q.front().F;
    int r = q.front().S;
    q.pop();
    for(int k = r + 1; k <= n; k++){
      if(pref[r] - pref[l - 1] <= pref[k] - pref[r]){
        dp[r + 1][k] = max(dp[r + 1][k], dp[l][r] + 1);
        if(k < n) q.push({r + 1, k});
      }
    }
  }
  for(int i = 1; i <= n; i++){
    ans = max(ans, dp[i][n]);
  }
  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...