| # | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 | 
|---|---|---|---|---|---|---|---|
| 708148 | arcane | Bigger segments (IZhO19_segments) | C++17 | 0 ms | 0 KiB | 
이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define mp make_pair
int32_t main(){
	ios::sync_with_stdio(false);
	cin.tie(0); cout.tie(0);
	int n, ans = 0, tmp1 = -1e8, tot, pos; cin >> n;
	int arr[n], smol[n], pref[n + 1]; 
	for (int i = 0; i < n; i++) cin >> arr[i];
	pref[0] = 0;
	set <pair <int, int> > s;
	for (int i = 0; i < n; i++) pref[i + 1] = pref[i] + arr[i];
	for (int i = 0; i < n; i++){
		smol[i] = pref[i + 1];
		auto it = s.upper_bound(mp(pref[i + 1], (int)1e18));
		if (it != s.begin()){
			it--;
			smol[i] = min(smol[i], pref[i + 1] + (*it).se);
		}
		s.insert(mp(smol[i] + pref[i + 1], -pref[i + 1]));
		while ((*(s.rbegin())).se != -pref[i + 1]) s.erase(--s.end());
	}
	tot = pref[n] - smol[n - 1]; pos = n - 1; ans = 1;
	while (tot){
		while (pref[pos + 1] != tot){
			pos--;
		}
		tot -= smol[pos]; ans += 1; 
	}
	cout << ans << '\n';
}
