Life Engineering
[BOJ 18111] 마인크래프트 (Java) 본문
https://www.acmicpc.net/problem/18111
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.StringTokenizer;
public class Main_BOJ_18111 {
static int N, M, B;
static int[][] map;
static int min=Integer.MAX_VALUE;
static int answer_height;
static int answer_time=Integer.MAX_VALUE;
public static void main(String[] args) throws IOException {
BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
StringTokenizer st=new StringTokenizer(br.readLine());
N=Integer.parseInt(st.nextToken());
M=Integer.parseInt(st.nextToken());
B=Integer.parseInt(st.nextToken());
map=new int[N][M];
for (int i=0; i<N; i++) {
st=new StringTokenizer(br.readLine());
for (int j=0; j<M; j++) {
map[i][j]=Integer.parseInt(st.nextToken());
if (min>map[i][j]) min=map[i][j];
}
}
for (int t=0; t<=256; t++) {
play(t);
}
System.out.println(answer_time+" "+answer_height);
}
private static void play(int t) {
int sum=0;
int block=0;
int toLoad=0;
for (int i=0; i<N; i++) {
for (int j=0; j<M; j++) {
if (map[i][j]>t) { //크다면 제거
sum+=(map[i][j]-t)*2;
block+=(map[i][j]-t);
}
else if (map[i][j]<t) { //작다면 넣어주기
toLoad+=(t-map[i][j]);
}
}
}
if (B+block<toLoad) return;
else {
sum+=(toLoad);
}
if (answer_time>=sum) { //최대한 큰 높이
answer_time=sum;
answer_height=t;
}
}
}
문제의 조건을 정확히 읽는게 중요했던 문제.
'Problem Solving' 카테고리의 다른 글
[BOJ 1918] 후위 표기식 (Java) (0) | 2022.03.22 |
---|---|
[BOJ 1967] 트리의 지름 (Java) (0) | 2022.03.22 |
[BOJ 16928] 뱀과 사다리 게임 (Java) (0) | 2022.03.20 |
[BOJ 2565] 전깃줄 (Java) (0) | 2022.03.17 |
[BOJ 2638] 치즈 (Java) (0) | 2022.03.17 |