https://www.acmicpc.net/problem/26215
26215번: 눈 치우기
집 2와 집 3 앞의 눈을 치우고, 집 2와 집 3 앞의 눈을 치우고, 집 1과 집 3 앞의 눈을 치운 뒤 집 3 앞의 눈을 두 번 치우면 5분만에 모든 집 앞의 눈을 치울 수 있다.
www.acmicpc.net
package BOJ.simulation;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.StringTokenizer;
import java.util.function.Function;
public class BOJ_26215 {
private static final int LIMIT = 1440;
private static final int ERROR = -1;
public static void main(String[] args) throws Exception {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
StringTokenizer st = new StringTokenizer(br.readLine());
Function<String,Integer> stoi = Integer::parseInt;
int n = stoi.apply(st.nextToken());
int[] num = new int[n];
st = new StringTokenizer(br.readLine());
int max = 0;
int sum = 0;
for(int i = 0 ; i < n ; i++){
num[i] = stoi.apply(st.nextToken());
sum += num[i];
max = Math.max(max,num[i]);
}
int remain = sum - max;
int result = sum / 2;
if(sum % 2 != 0){
result++;
}
if(max > remain){
result = max;
}
if(result > LIMIT){
System.out.println(ERROR);
}else{
System.out.println(result);
}
}
}
'알고리즘' 카테고리의 다른 글
백준 25916번 싫은데요 (JAVA) (0) | 2023.02.10 |
---|---|
백준 진우의 달 여행 (JAVA) (0) | 2023.02.09 |
백준 8911번 거북이 (JAVA) (0) | 2023.02.07 |
백준 25214번 크림 파스타(JAVA) (0) | 2023.02.06 |
백준 15645번 내려가기2(JAVA) (0) | 2023.02.05 |