-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathP18111.cpp
56 lines (44 loc) · 1.21 KB
/
P18111.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
#include <iostream>
#define REMOVE 2
#define ADD 1
using namespace std;
int map[501][501] = {};
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
int N, M, B;
cin >> N >> M >> B;
int min_height = 987654321;
int max_height = 0;
for (int i = 0; i < N; i++) {
for (int j = 0; j < M; j++) {
cin >> map[i][j];
min_height = min(min_height, map[i][j]);
max_height = max(max_height, map[i][j]);
}
}
int min_time = 987654321, height = 0;
for (int k = min_height; k <= max_height; k++) {
int inventory = B, time = 0;
for (int i = 0; i < N; i++) {
for (int j = 0; j < M; j++) {
auto temp = map[i][j] - k;
if (temp > 0) {
time += temp * REMOVE;
inventory += temp;
} else if (temp < 0) {
time += temp * ADD * -1;
inventory += temp;
}
}
}
if(inventory < 0) continue;
if(time <= min_time) {
min_time = time;
height = k;
}
}
cout << min_time << " " << height;
return 0;
}