Notice
Recent Posts
문제 풀이 및 개발 공간
[백준] 26215번 눈 치우기 (silver 3 본문
import java.io.*;
import java.util.*;
public class Main{
public static void main(String[] args) throws IOException{
BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
BufferedWriter bw=new BufferedWriter(new OutputStreamWriter(System.out));
int n=Integer.valueOf(br.readLine());
PriorityQueue<Integer> que=new PriorityQueue<>(Collections.reverseOrder());
StringTokenizer st=new StringTokenizer(br.readLine());
for(int i=0; i<n; i++){
que.offer(Integer.valueOf(st.nextToken()));
}
int time=0;
//작은 경우부터 뽑으면, 큰 경우를 하나씩만 뽑게되는 경우 발생.
//큰 경우가 우선순위로 정렬.
//2개를 제거 가능하면 2개.
//그게아니면 1개씩 제거해나가기.
while(!que.isEmpty()){
if(que.size()>=2) {
int a = que.poll() - 1;
int b = que.poll() - 1;
if (a > 0) {
que.offer(a);
}
if (b > 0) {
que.offer(b);
}
}
else if(que.size()>=1) {
int c = que.poll() - 1;
if (c > 0) {
que.offer(c);
}
}
time++;
}
bw.write(time>1440 ? "-1" : time+"");
bw.flush();
}
}
'백준공부 > java' 카테고리의 다른 글
[백준] 10775번 공항 (gold 2 (0) | 2024.03.19 |
---|---|
[백준] 1969번 DNA (silver 4 (0) | 2024.03.18 |
[백준] 1202번 보석 도둑 (gold 2 (0) | 2024.03.18 |
[백준] 2437번 저울 (gold 2 (0) | 2024.03.17 |
[백준] 1005번 ACM Craft (gold 3 (3) | 2024.03.17 |