Cod sursa(job #2521035)

Utilizator Data 10 ianuarie 2020 12:05:16 Balans 70 cpp-64 done Arhiva de probleme 1.27 kb
``````#include <iostream>
#include <iomanip>
#include <cstdio>

using namespace std;

typedef long long ll;
const int N = 300 + 7;
int n, m, x, y;
int a[N][N];
ll c[N][N];
ll mn[N];

bool ok(int num) {
for (int i = 1; i <= n; i++) {
for (int j = 1; j <= m; j++) {
c[i][j] = a[i][j] - num + c[i][j - 1];
}
}

for (int l = 1; l <= m; l++) {
for (int r = l + y - 1; r <= min(m, r + 10); r++) {
ll cur = 0;
for (int i = 1; i <= n; i++) {
cur += c[i][r] - c[i][l - 1];
mn[i] = min(mn[i - 1], cur);
if (i >= x && cur - mn[i - x] >= 0LL) {
return 1;
}
}
}
}
return 0;
}

int main() {
freopen ("balans.in", "r", stdin);
freopen ("balans.out", "w", stdout);

cin >> n >> m >> x >> y;
for (int i = 1; i <= n; i++) {
for (int j = 1; j <= m; j++) {
cin >> a[i][j];
a[i][j] *= 1000;
a[i + n][j] = a[i][j + m] = a[i + n][j + m] = a[i][j];
}
}

n *= 2;
m *= 2;

int l = 0, r = 100000000, ans = 0;
while (l <= r) {
int mid = (l + r) / 2;
if (ok(mid)) {
ans = mid;
l = mid + 1;
} else {
r = mid - 1;
}
}

cout << fixed << setprecision(3) << ans / 1000.0 << "\n";

return 0;
}``````