제출 #883254

#제출 시각아이디문제언어결과실행 시간메모리
883254OAleksaBigger segments (IZhO19_segments)C++14
0 / 100
1 ms348 KiB
#include<bits/stdc++.h>
using namespace std;
#define f first
#define s second
#define int long long
const int maxn = 2010;
const int inf = 1e15;
int a[maxn], l, r, n, p[maxn];
signed main() {
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
  int tt = 1;
  //cin >> tt;
  while (tt--) {
   	int n;
   	cin >> n;
   	vector<int> a(n);
   	for (int i = 0;i < n;i++)
   		cin >> a[i];
   	int sm = a[0], c = 0, l = 1, r = 1;
   	vector<pair<int, int>> ans;
   	ans.push_back({0, 0});
   	while (r < n) {
   		c += a[r];
   		if (c < sm) {
   			r++;
   			if (r == n) {
   				int x = ans.back().s;
   				while (x > ans.back().f && c < sm) {
   					c += a[x];
   					sm -= a[x];
   					--x;
   				}
   				if (c >= sm)
   					ans.push_back({x, r});
   			}
   			continue;
   		}
   		assert(c >= sm);
   		while (sm + a[r] <= c - a[r]) {
   			sm += a[r];
   			c -= a[r];
   			r--;
   		}
   		while (sm + a[l] <= c - a[l]) {
   			sm += a[l];
   			c -= a[l];
   			l++;
   		}
			ans.push_back({l, r});
   		l = r + 1;
   		r++;
   		sm = c;
   		c = 0;
   	}
   	cout << ans.size();
	}
	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...