-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathOutOfSorts.java
More file actions
33 lines (32 loc) · 1.03 KB
/
Copy pathOutOfSorts.java
File metadata and controls
33 lines (32 loc) · 1.03 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
import java.io.*;
import java.util.*;
public class OutOfSorts {
public static void main(String[] args) throws IOException {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
PrintWriter pw = new PrintWriter(System.out);
int n = Integer.parseInt(br.readLine());
Entry[] entries = new Entry[n];
for(int i=0; i<n; i++) {
entries[i] = new Entry(Integer.parseInt(br.readLine()), i);
}
Arrays.sort(entries);
int ans = 1;
for(int i=0; i<n; i++) {
ans = Math.max(ans, 1 + entries[i].index - i);
}
pw.println(ans);
pw.close();
}
static class Entry implements Comparable<Entry>{
int val;
int index;
public Entry(int val, int index) {
this.val = val;
this.index = index;
}
public int compareTo(Entry other) {
if(this.val == other.val) return this.index - other.index;
return this.val - other.val;
}
}
}