Skip to content

Commit 6932702

Browse files
committed
With greedy algorithm
1 parent 2d0e46d commit 6932702

1 file changed

Lines changed: 23 additions & 0 deletions

File tree

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
import java.awt.*;
2+
import java.util.*;
3+
4+
public class P11509 {
5+
public static void main(String[] args){
6+
Scanner sc=new Scanner(System.in);
7+
8+
int n=sc.nextInt();
9+
int[] h=new int[1000001];
10+
int cnt=0;
11+
for(int i=0;i<n;i++){
12+
int data=sc.nextInt();
13+
if(h[data]==0){
14+
cnt++;
15+
}
16+
else{
17+
h[data]--;
18+
}
19+
if(data-1>0) h[data-1]++;
20+
}
21+
System.out.println(cnt);
22+
}
23+
}

0 commit comments

Comments
 (0)