Submission #231351

#TimeUsernameProblemLanguageResultExecution timeMemory
231351maskoffBigger segments (IZhO19_segments)C++14
37 / 100
1591 ms3840 KiB
#include <bits/stdc++.h>
#include <ext/rope>
#include <random>
#include <chrono>
#include <ext/pb_ds/assoc_container.hpp>
 
#define file ""
 
#define all(x) x.begin(), x.end()
 
#define sc second
#define fr first
 
#define pb push_back
#define mp make_pair

#define pss pair<line*, line*>
 
using namespace std;
using namespace __gnu_cxx;
 
typedef long long ll;
typedef pair <int, int> pii;
                                    
const int inf = 1e9;
const int MOD = 1e9 + 7;
                                          
const int dx[] = {+1, -1, 0, 0};
const int dy[] = {0, 0, +1, -1};

int const N = 5e5 + 1;

int main() {   
	ios_base :: sync_with_stdio(false);
  cin.tie(nullptr);
  int n;
  cin >> n;
  vector<ll> a(n + 1), pref(n + 1);
  for (int i = 1; i <= n; i++)
  	cin >> a[i];
  for (int i = 1; i <= n; i++)
  	pref[i] = pref[i - 1] + a[i];
  vector<pair<ll, ll>> dp(n + 1);

  for (int i = 1; i <= n; i++) {
   	for (int j = 0; j < i; j++) {
   	 	if (pref[i] - pref[j] >= dp[j].sc) {
   	 		if (dp[j].fr + 1 >= dp[i].fr) {
   	 		 	dp[i].fr = dp[j].fr + 1;
   	 			dp[i].sc = pref[i] - pref[j];
   	 		}
   	 	}
   	}
  }
  /*for (int i = 1; i <= n; i++) {
   	cout << dp[i].fr << " " << dp[i].sc << endl;
  }              */
  cout << dp[n].fr;
	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...