#include<bits/stdc++.h>
using namespace std;
const int N = 1e3 + 5;
int m, n, k;
int a[N][N], b[N][N], c[N][N];
int st[N], bot, top;
void nhap()
{
cin >> m >> n >> k;
for(int i = 1; i <= m; i++)
for(int j = 1; j <= n; j++)
cin >> a[i][j];
}
void giai()
{
for(int j = 1; j <= n; j++)
{
bot = 1; top = 0;
for(int i = 1; i <= m; i++)
{
while( bot <= top && st[bot] < i-k+1 ) bot++;
while( bot <= top && a[st[top]][j] >= a[i][j] ) top--;
st[++top] = i;
b[i][j] = a[st[bot]][j];
}
}
for(int i = 1; i <= m; i++)
{
bot = 1; top = 0;
for(int j = 1; j <= n; j++)
{
while( bot <= top && st[bot] < j-k+1 ) bot++;
while( bot <= top && b[i][st[bot]] >= b[i][j] ) top--;
st[++top] = j;
c[i][j]=b[i][st[bot]];
// if( i >= k && j >= k )
// res = max(res, b[i][st[bot]]);
}
}
int res = 0;
for(int i=k;i<=m;i++)
for(int j=k;j<=n;j++) res=max(res,c[i][j]);
cout << res;
}
int main()
{
freopen("hvcon.inp","r",stdin);
freopen("hvcon.out","w",stdout);
ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
nhap();
giai();
}
* Chuyên dạy lập trình ONLINE cho học sinh THCS, THPT *.
Mọi giao lưu, trao đổi, xin liên hệ: Lê Quang Vinh - zalo: 037.803.8755.
Page: Lớp học Code Sky
Group FB1: Ôn thi HSG9 - THTB - TS10 chuyên tin
Group FB2: Học Scratch - Ôn thi Tin học trẻ bảng A
Thứ Hai, 24 tháng 1, 2022
hvcon c++
Đăng ký:
Đăng Nhận xét (Atom)
Không có nhận xét nào:
Đăng nhận xét
Lưu ý: Chỉ thành viên của blog này mới được đăng nhận xét.