Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.io.*;
- import java.util.*;
- public class Swordfish {
- public static void main(String[] args) throws Exception {
- new Main().run();
- }
- }
- class Main {
- BufferedReader reader;
- StringTokenizer st;
- PrintWriter out;
- Integer n, cnt;
- Integer[] place, answer;
- void run() throws Exception {
- out = new PrintWriter(new FileWriter("race.out"));
- reader = new BufferedReader(new FileReader("race.in"));
- n = Integer.decode(reader.readLine());
- place = new Integer[n];
- answer = new Integer[n];
- cnt = 0;
- answer[cnt++] = n - 1;
- st = new StringTokenizer(reader.readLine());
- for (int i = 0; i < n; i++) {
- place[i] = Integer.decode(st.nextToken()) - 1;
- }
- int m = place[n - 1];
- for (int k = n - 2; k >= 0; k--) {
- if (m == k + 1) {
- answer[cnt++] = k;
- }
- if (place[k] < m)
- m = place[k];
- }
- out.printf("%d%n", cnt);
- for (int i = cnt - 1; i >= 0; i--)
- out.printf("%d ", answer[i] + 1);
- out.printf("%n");
- reader.close();
- out.close();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement