https://zerojudge.tw/ShowProblem?problemid=f313```cpp=
#include <bits/stdc++.h>
using namespace std;
/*
2 3 4 1
10 2 -1
5 -1 2
*/
int main(){
int r, c, k, m; cin>>r>>c>>k>>m;
//int arr[r][c];
vector<vector<int>> arr(r, vector<int>©);
vector<vector<int>> brr(r, vector<int>©);
for(int i=0; i<r; i++){
for(int j=0; j<c; j++){
cin>>arr[i][j];
}
}
while(m--){
brr = arr;
for(int i=0; i<r; i++){
for(int j=0; j<c; j++){
if(arr[i][j] == -1 ) continue;
int yee = arr[i][j] / k;
int cnt = 0;
if( i!=0 ){
if(arr[i-1][j] == -1 ) continue;
brr[i-1][j] += yee;
cnt += yee;
}
if( i!=(r-1) ){
if(arr[i+1][j] == -1 ) continue;
brr[i+1][j] += yee;
cnt += yee;
}
if( j!=0 ){
if(arr[i][j-1] == -1 ) continue;
brr[i][j-1] += yee;
cnt += yee;
}
if( j!=(c-1) ){
if(arr[i][j+1] == -1 ) continue;
brr[i][j+1] += yee;
cnt += yee;
}
brr[i][j] -= cnt;
}
}
arr = brr;
/*
cout << "===\n";
for(int i = 0; i < r; ++i)
{
for(int j = 0; j < c; ++j)
cout << arr[i][j] << " ";
cout << "\n";
}
cout << "===\n\n";
*/
}
int MAX = 0;
int MIN = INT_MAX;
for(int i=0; i<r; i++){
for(int j=0; j<c; j++){
if(arr[i][j] == -1 ) continue;
MIN = min(MIN, arr[i][j]);
MAX = max(MAX, arr[i][j]);
// cout<<MIN<<' '<<MAX<<'\n';
}
}
cout<<MIN<<endl<<MAX;
}