728x90
반응형
https://www.acmicpc.net/problem/2847
class Main {
public static void main(String[] args) throws IOException {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
int length = Integer.valueOf(br.readLine());
int[] tt = new int[length];
for (int i=0;i<length;i++) {
tt[i]= Integer.valueOf(br.readLine());
}
int count=0;
// 반복문은 높은 레벨부터 검사한다.
for (int i=tt.length-1; i >= 1 ; i--) {
// 높은 레벨보다 아래 레벨의 점수가 높다면,
if ( tt[i-1] >= tt[i]){
// 카운트++;
count += 1;
tt[i-1]-=1;
// 다시 낮아질때까지 검사해야니까 index--;
i++;
}
}
System.out.println(count);
}
}
320x100
반응형
'ALGORITHM' 카테고리의 다른 글
DFS java (0) | 2022.06.17 |
---|---|
JAVA 미로탐색 / BFS (0) | 2022.06.14 |
SHA-256 (Secure Hash Algorithm) (0) | 2022.04.04 |
완전탐색 / 모의고사 (0) | 2022.03.23 |
Big O / 시간복잡도 / Binary Search / Linear Search (0) | 2022.03.20 |