Skip to content

Commit 511de0c

Browse files
committed
BOJ_18111 : 마인크래프트
1 parent 2dacce4 commit 511de0c

File tree

1 file changed

+50
-0
lines changed

1 file changed

+50
-0
lines changed
+50
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
import java.io.*;
2+
import java.util.*;
3+
4+
public class Main {
5+
6+
public static void main(String[] args) throws IOException {
7+
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
8+
StringTokenizer st = new StringTokenizer(br.readLine());
9+
int N = Integer.parseInt(st.nextToken());
10+
int M = Integer.parseInt(st.nextToken());
11+
int B = Integer.parseInt(st.nextToken());
12+
int[][] arr = new int[N][M];
13+
int max = Integer.MIN_VALUE;
14+
int min = Integer.MAX_VALUE;
15+
for(int i=0; i<N; i++) {
16+
st = new StringTokenizer(br.readLine());
17+
for(int j=0; j<M; j++) {
18+
arr[i][j] = Integer.parseInt(st.nextToken());
19+
max = Math.max(max, arr[i][j]);
20+
}
21+
}
22+
int height = 0;
23+
for(int i=0; i<=max; i++) {
24+
int stackBlock = 0;
25+
int removeBlock = 0;
26+
for(int j=0; j<N; j++) {
27+
for(int k=0; k<M; k++) {
28+
if(arr[j][k] < i) {
29+
stackBlock += i - arr[j][k];
30+
}else {
31+
removeBlock += arr[j][k] - i;
32+
}
33+
}
34+
}
35+
if(stackBlock > removeBlock + B) {
36+
continue;
37+
}
38+
int time = stackBlock + 2*removeBlock;
39+
if(min >= time) {
40+
if(min == time) {
41+
height = Math.max(height, i);
42+
}else {
43+
height = i;
44+
}
45+
min = time;
46+
}
47+
}
48+
System.out.println(min + " " + height);
49+
}
50+
}

0 commit comments

Comments
 (0)