輸出最小值小心-1~~~~
#include <bits/stdc++.h>
#define fast_as_a_fuckboy ios_base::sync_with_stdio(0); cin.tie(0);
using namespace std;
int main() {
fast_as_a_fuckboy
int r, c, k, m;
cin >> r >> c >> k >> m;
int a[r][c];
int move[r][c];
for(int i = 0;i < r;i++){
for(int j = 0;j < c;j++){
cin >> a[i][j];
}
}
for(int K = 0;K < m;K++){ //先算每個城市要移動多少人
memset(move, 0, sizeof(move));//初始化move陣列
for(int i = 0;i < r;i++){
for(int j = 0;j < c;j++){
if(a[i][j] <= 0){
continue;
}
else{
move[i][j] = a[i][j] / k;
}
}
}
for(int i = 0;i < r;i++){//計算每個城市移動的人
for(int j = 0;j < c;j++){
if(a[i+1][j] != -1 && (i+1) < r){a[i+1][j] += move[i][j];a[i][j] -= move[i][j];}
if(a[i][j+1] != -1 && (j+1) < c){a[i][j+1] += move[i][j];a[i][j] -= move[i][j];}
if(a[i-1][j] != -1 && (i-1) >= 0){a[i-1][j] += move[i][j];a[i][j] -= move[i][j];}
if(a[i][j-1] != -1 && (j-1) >= 0){a[i][j-1] += move[i][j];a[i][j] -= move[i][j];}
}
}
}
int mx = 0, mn = INT_MAX;
for(int i = 0;i < r;i++){
for(int j = 0;j < c;j++){
mx = max(mx,a[i][j]);
if(a[i][j] != -1){
mn = min(mn,a[i][j]);
}
}
}
cout << mn << "\n" << mx;
}