# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
1130338 | bachnv | Quality Of Living (IOI10_quality) | C++20 | 0 ms | 0 KiB |
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
ll n, m, h, w, x, pfs[3005][3005], q[3005][3005];
ll cmp(ll temp){
if(temp == x){
return 0;
}
else if(temp < x){
return 1;
}
else{
return -1;
}
}
bool check(){
memset(pfs, 0, sizeof(pfs));
for(int i = 0; i < n; i++){
for(int j = 0; j < m; j++){
pfs[i][j] = cmp(q[i][j]);
if(i){
pfs[i][j] += pfs[i - 1][j];
}
if(j){
pfs[i][j] += pfs[i][j - 1];
}
if(i && j){
pfs[i][j] -= pfs[i - 1][j - 1];
}
}
}
for(int i = 0; i + h - 1 < n; i++){
for(int j = 0; j + w - 1 < m; j++){
ll temp = pfs[i + h - 1][j + w - 1];
if(i){
temp -= pfs[i - 1][j + w - 1];
}
if(j){
temp -= pfs[i + h - 1][j - 1];
}
if(i && j){
temp += pfs[i - 1][j - 1];
}
if(temp >= 0){
return true;
}
}
}
return false;
}
int main(){
cin >> n >> m >> h >> w;
for(int i = 0; i < n; i++){
for(int j = 0; j < m; j++){
cin >> q[i][j];
}
}
ll res;
ll l = 1, r = n * m;
while(l <= r){
x = (l + r) / 2;
if(check()){
res = x;
r = x - 1;
}
else{
l = x + 1;
}
}
cout << res;
}