This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <iostream>
#include <cmath>
#include <stdio.h>
#include <array>
#include <vector>
#include <list>
#include <algorithm>
#include <utility>
#include <string>
#include <sstream>
#include <map>
#include <queue>
#include <stack>
#include <set>
#include <unordered_set>
#include <unordered_map>
#include <iomanip>
#define pp pair<int,int>
#define pll pair<ll, ll>
#define ll long long
using namespace std;
map<int, int> checking;
ll prefix[300001];
int main() {
//freopen(".in", "r", stdin);
//freopen(".out", "w", stdout);
ll n;
cin >> n;
ll maxi = 0;
for (int i = 1; i < n; i++) {
ll a;
cin >> a;
prefix[i] = prefix[i-1]+a;
maxi = max(prefix[i], maxi);
}
int index1 = 0;
for (int i = 1; i < n; i++) {
if (maxi == prefix[i]) {
index1 = i;
break;
}
}
int amount = n-prefix[index1];
int answers[n];
answers[0] = amount;
checking[amount] = 1;
for (int i = 1; i < n; i++) {
if (i == n-1) {
if (checking.find(amount+prefix[i]) == checking.end()) {
answers[i] = amount+prefix[i];
checking[amount+prefix[i]] = 1;
} else {
cout << "-1" << endl;
return 0;
}
} else {
if (checking.find(amount+prefix[i]) == checking.end()) {
answers[i] = amount+prefix[i];
checking[amount+prefix[i]] = 1;
} else {
cout << "-1" << endl;
return 0;
}
}
}
for (int i = 0; i < n; i++) {
if (i == 1) {
cout << answers[i] << endl;
} else {
cout << answers[i] << " ";
}
}
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |