File tree 1 file changed +50
-0
lines changed
1 file changed +50
-0
lines changed Original file line number Diff line number Diff line change
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
+ }
You can’t perform that action at this time.
0 commit comments