This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
import java.util.*;
import java.io.*;
public class Labels {
static class Reader {
final private int BUFFER_SIZE = 1 << 16;
private DataInputStream din;
private byte[] buffer;
private int bufferPointer, bytesRead;
public Reader() {
din = new DataInputStream(System.in);
buffer = new byte[BUFFER_SIZE];
bufferPointer = bytesRead = 0;
}
public int ni() throws IOException {
int ret = 0;
boolean flip = false;
byte c = read();
while (c < '0' || c > '9') {
if (c == '-') flip = true;
c = read();
}
do {
ret = ret * 10 + c - '0';
} while ((c = read()) >= '0' && c <= '9');
return flip ? -ret : ret;
}
public long nl() throws IOException {
long ret = 0;
boolean flip = false;
byte c = read();
while (c < '0' || c > '9') {
if (c == '-') flip = true;
c = read();
}
do {
ret = ret * 10 + c - '0';
} while ((c = read()) >= '0' && c <= '9');
return flip ? -ret : ret;
}
private void fillBuffer() throws IOException
{
bytesRead = din.read(buffer, bufferPointer = 0, BUFFER_SIZE);
if (bytesRead == -1) {
buffer[0] = -1;
}
}
private byte read() throws IOException
{
if (bufferPointer == bytesRead) {
fillBuffer();
}
return buffer[bufferPointer++];
}
}
public static void main(String[] args) throws IOException {
Reader sc = new Reader();
PrintStream out = new PrintStream(new BufferedOutputStream(System.out));
int N = sc.ni(); // read an integer
int[] arr = new int[N];
int min = 0;
int max = 0;
for (int i = 1; i < N; i++) {
arr[i] = arr[i-1]+sc.ni();
min = Math.min(arr[i],min);
max = Math.max(arr[i],max);
}
if (max-min == N-1) {
int add = 1-min;
for (int i = 0; i < N; i++) {
out.print((arr[i]+add) + " ");
}
} else {
out.print("-1");
}
out.flush(); // remember to flush just once, at the very end of your program
}
}
# | 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... |