Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Latest commit

 

History

History
History
74 lines (68 loc) · 1.54 KB

File metadata and controls

74 lines (68 loc) · 1.54 KB
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
/*
* Author: Amitrajit Bose
* Problem Link: https://www.codechef.com/problems/EQUALIZE
* Approach: Binary
*/
#include<bits/stdc++.h>
#include <iostream>
#include<ctype.h>
#include<climits>
using namespace std;
typedef long long ll;
#define rep(m,n) for(i=m; i<(n); i++)
#define test ll t; cin>>t; while(t--)
int h[1001][1001];
int t[1001][1001];
int main()
{
int n,m,query;
cin >> n >> m >> query;
for(int i=1;i<=n;i++)
{
for(int j=1;j<=m;j++)
{
cin >> h[i][j];
}
}
// processing queries
int k,l;
for(int i=0; i<query;i++)
{
cin >> k >> l;
int low=0;
int high=10000000;
int cnt = (k*l)/2 +1;
k--;
l--;
while(low<high)
{
int mid = (low+high+1)/2;
for(int p=1;p<=n;p++)
{
for(int q=1;q<=m;q++)
{
t[p][q] = t[p-1][q]+t[p][q-1]-t[p-1][q-1]+(h[p][q]>=mid?1:0);
}
}
int flag=1;
for(int p=1;(p+k)<=n;p++)
{
for(int q=1;(q+l)<=m;q++)
{
if((t[p+k][q+l] - t[p-1][q+l] - t[p+k][q-1] + t[p-1][q-1]) >= cnt)
{
low=mid;
flag=0;
break;
}
}
if(!flag)
break;
}
if(flag)
high=mid-1;
}
cout << low << endl;
}
return 0;
}
Morty Proxy This is a proxified and sanitized view of the page, visit original site.