제출 #335758

#제출 시각아이디문제언어결과실행 시간메모리
335758AgnimandurLabels (NOI20_labels)Java
100 / 100
664 ms21088 KiB
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 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...