import java.util.Scanner; //implement SlidingWindow // solution: class SlidingWindow { int buf[]; // data buffer int size; // how many elements of the buffer are used int position; // current insertion position of the buffer public SlidingWindow(int size) { buf = new int[size]; position = 0; size = 0; } // post: value added to internal buffer public void Put(int value) { buf[position] = value; position = (position + 1) % buf.length; if (size < buf.length) size++; } // pre: some data have been provided via put // post: returns minimum of the most recent data in the buffer public int Min() { int min = buf[0]; for (int i = 1; i < size; ++i) { if (buf[i] < min) min = buf[i]; } return min; } // pre: some data have been provided via put // post: returns minimum of the most recent data in the buffer public int Max() { int max = buf[0]; for (int i = 1; i < size; ++i) { if (buf[i] > max) max = buf[i]; } return max; } } class Main { // this is the test code for the judge, do not modify public static void main(String[] args) { Scanner scanner = new Scanner(System.in); int windowSize = scanner.nextInt(); SlidingWindow window = new SlidingWindow(windowSize); while (scanner.hasNextInt()) { int value = scanner.nextInt(); window.Put(value); System.out.println("[" + window.Min() + " " + window.Max() + "]"); } scanner.close(); } }