Submission #541035

#TimeUsernameProblemLanguageResultExecution timeMemory
541035bayemirovLabels (NOI20_labels)C++17
100 / 100
91 ms6684 KiB
// bayemirov

#include <bits/stdc++.h>

using namespace std;

#define pb push_back

const int N = 5e5+9;

int n, a[N], p[N], mx=-1, mn=1e18;

int main() {
	ios_base::sync_with_stdio(0);
	cin.tie(0); cout.tie(0);
	cin >> n;
	for (int i = 1; i <= n-1; i++) {
		cin >> a[i];
		p[i] = p[i-1] + a[i];
		mx = max(mx, p[i]);
		mn = min(mn, p[i]);
	}
	int ans = -1, cnt = 0;
	for (int l = 1; l <= n; l++) {
		if (l + mx <= n && l + mn >= 1) {
			ans = l;
			cnt++;
		}
	}
	if (ans == -1 || cnt != 1) cout << -1, exit(false);
	cout << ans << ' ';
	for (int i = 1; i <= n-1; i++) {
		ans += a[i];
		cout << ans << ' ';
	}
	return 0;
}

Compilation message (stderr)

Labels.cpp:11:30: warning: overflow in conversion from 'double' to 'int' changes value from '1.0e+18' to '2147483647' [-Woverflow]
   11 | int n, a[N], p[N], mx=-1, mn=1e18;
      |                              ^~~~
#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...