algorithm'''problem solve
[백준]18111-마인크래프트(설명X)
JunHwa Park
2020. 2. 2. 15:30
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 | #include <iostream> #include <cstdio> using namespace std; int sub_arr(int** arr, int N, int M, int B, int height) { int minus = 0, plus = 0; for (size_t i = 0; i < N; i++) for (size_t j = 0; j < M; j++) { arr[i][j] -= height; if (arr[i][j] > 0) plus += arr[i][j]; else minus -= arr[i][j]; } if (minus > B + plus) return -1; else return plus * 2 + minus; } int main() { int N, M, B; int min = 500, max = 0; scanf("%d %d %d", &N, &M, &B); int** height = new int*[N]; for (size_t i = 0; i < N; i++) { height[i] = new int[M]; for (size_t j = 0; j < M; j++) { scanf("%d", &height[i][j]); if (min > height[i][j]) min = height[i][j]; else if (max < height[i][j]) max = height[i][j]; } } sub_arr(height, N, M, B, min - 1); size_t time = UINT32_MAX, h = 0; for (size_t i = 0; i <= max - min; i++) { int t = sub_arr(height, N, M, B, 1); if (time >= t && t != -1) { time = t; h = min + i; } } printf("%u %d", time, h); return 0; } | cs |