# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
1174977 | vahagng | Quality Of Living (IOI10_quality) | C++20 | 0 ms | 0 KiB |
#include "quality.h"
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define all(v) v.begin(),v.end()
ll pref[110][110];
ll check(ll x){
for(int i = 0; i <= n; i++){
for(int j = 0; j <= m; j++){
pref[i][j] = 0;
}
}
for(int i = 1; i <= n; i++){
for(int j = 1; j <= m; j++){
pref[i][j] = pref[i-1][j] + pref[i][j-1] - pref[i-1][j-1] + (a[i][j] <= x ? 1 : -1);
}
}
auto qry = [&](int x1, int y1, int x2, int y2){
return pref[x2][y2] - pref[x1-1][y2] - pref[x2][y1-1] + pref[x1-1][y1-1];
};
ll mx = -h*w;
for(int x1 = 1, x2 = h; x2 <= n; x1++, x2++){
for(int y1 = 1, y2 = w; y2 <= m; y1++, y2++){
mx = max(mx, qry(x1,y1,x2,y2));
}
}
return mx;
}
int rectangle(int n, int m, int h, int w, int a[3001][3001]) {
for(int i = 1; i <= n*m; i++){
if(check(i) > 0) return i;
}
}