Submission #1065926

#TimeUsernameProblemLanguageResultExecution timeMemory
1065926Shadow1Labels (NOI20_labels)C++17
100 / 100
47 ms6828 KiB
// Programmer: Shadow1

#include <bits/stdc++.h>
using namespace std;

using ll = long long;
using ld = long double;
using ull = unsigned long long;
using str = string; // yay python!

#define i64 int64_t
#define watch(x) cerr << (#x) << " = " << (x) << '\n';
#define output_vector(v) for(auto &x : v){cout << x << " ";}cout << '\n';
#define vt vector
#define st stack
#define pq priority_queue
#define pb push_back
#define eb emplace_back
#define pii pair<int,int>
#define umap unordered_map
#define uset unordered_set
#define fir first
#define sec second
#define sz(x) int(x.size())
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()


// T: O(n^3)
// M : O(n + k log n)

void solve() {
	int n;
	cin >> n;
	vector<int> d(n-1), ans(n);
	for(auto &D : d) {
		cin >> D;
	}
	int64_t mx = 0, mn = 0;
	int64_t sum = 0;
	for(auto &D : d) {
		sum += D;
		mx = max(mx, sum);
		mn = min(mn, sum);
	}
	// watch(mx);
	// watch(mn);
	if(mx - mn == n-1) {
		ans[0] = n - mx;
		for(int i=1; i<n; ++i) {
			ans[i] = d[i-1] + ans[i-1];
		}
		output_vector(ans);
	} else {	
		cout << -1 << '\n';
	}
	
}

int main() {
	// freopen("output.txt", "w", stdout);
	// freopen("input.txt", "r", stdin);
	ios::sync_with_stdio(false);
	cin.tie(NULL); 
	
	solve();
	return 0;
}

/* CHECK :
1. COMPARATOR FUNCTION MUST RETURN FALSE WHEN ARGUMENTS ARE EQUAL!!!
2. Overflow! Typecase int64_t on operations if varaibles are int
3. Check array bounds!!!
4. Check array indexing!!!
5. Edge cases. (N==1)!!!
*/
#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...