728x90
📑문제링크
https://www.acmicpc.net/problem/11509
💻코드
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.StringTokenizer;
public class Main {
public static void main(String[] args) throws IOException {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
int N = Integer.parseInt(br.readLine());
StringTokenizer st = new StringTokenizer(br.readLine());
int[] balloon = new int[N];
for (int i = 0; i < N; i++) {
balloon[i] = Integer.parseInt(st.nextToken());
}
int answer = 0;
int[] arrow = new int[1000002];
for (int i = 0; i < N; i++) {
if(arrow[balloon[i]]>0){
arrow[balloon[i]]--;
arrow[balloon[i]-1]++;
}else{
answer++;
arrow[balloon[i]-1]++;
}
}
System.out.println(answer);
}
}
728x90
'Algorithm > Baekjoon' 카테고리의 다른 글
[Algorithm/Baekjoon] 떡 돌리기 - 20007 (S1/JAVA) (0) | 2024.10.07 |
---|---|
[Algorithm/Baekjoon] 오르막 수 - 11057 (S1/JAVA) (0) | 2024.09.30 |
[Algorithm/Baekjoon] 거의 소수 - 1456 (G5/JAVA) (0) | 2024.09.09 |
[Algorithm/Baekjoon] 부분수열의 합 - 1182 (S2/JAVA) (1) | 2024.09.02 |
[Algorithm/Baekjoon] 예산 - 2512 (S2/JAVA) (2) | 2024.03.20 |