Submission #342532

# Submission time Handle Problem Language Result Execution time Memory
342532 2021-01-02T10:35:30 Z SeDunion Bigger segments (IZhO19_segments) C++17
0 / 100
0 ms 364 KB
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
const int N = 5e5 + 55;

int a[N];

int main() {
	ios_base::sync_with_stdio(0);
	cin.tie(0), cout.tie(0);
	int n;
	cin >> n;
	for (int i = 1 ; i <= n ; ++ i) cin >> a[i];
	int ans = 0;
	{
		ll S = 0;
		const int K = min(n, 3000);
		for (int s = 1 ; s <= K ; ++ s) {
			S += a[s];
			int cur = 1;
			ll P = S, T = 0;
			for (int i = s + 1 ; i <= n ; ++ i) {
				T += a[i];
				if (T >= P) {
					P = T;
					T = 0;
					cur++;
				}
			}
			ans = max(ans, cur);
		}

	}
	for (int i = 1 ; i <= n ; ++ i) a[i] = -a[i];
	reverse(a + 1, a + 1 + n);
	{
		ll S = 0;
		const int K = min(n, 3000);
		for (int s = 1 ; s <= K ; ++ s) {
			S += a[s];
			int cur = 1;
			ll P = S, T = 0;
			for (int i = s + 1 ; i <= n ; ++ i) {
				T += a[i];
				if (T >= P) {
					P = T;
					T = 0;
					cur++;
				}
			}
			ans = max(ans, cur);
		}

	}
	cout << ans;
}
# Verdict Execution time Memory Grader output
1 Correct 0 ms 364 KB Output is correct
2 Incorrect 0 ms 364 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 364 KB Output is correct
2 Incorrect 0 ms 364 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 364 KB Output is correct
2 Incorrect 0 ms 364 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 364 KB Output is correct
2 Incorrect 0 ms 364 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 364 KB Output is correct
2 Incorrect 0 ms 364 KB Output isn't correct
3 Halted 0 ms 0 KB -