# Cod sursa(job #2640958)

Utilizator Data 9 august 2020 13:05:52 Balans 0 cpp-64 done Arhiva de probleme 1.04 kb
``````#include <fstream>
#include <iomanip>

using namespace std;

ifstream cin ("balans.in");
ofstream cout ("balans.out");

int n, m, r, c;
long double ans;

int v[305][305];
long long sp[305][305];

int main() {
cin >> n >> m >> r >> c;
for(int i = 1; i <= 2 * n; i++) {
for(int j = 1; j <= 2 * m; j++) {
if(i <= n && j <= m) {
cin >> v[i][j];
v[i + n][j] = v[i][j + m] = v[i + n][j + m] = v[i][j];
}
sp[i][j] = sp[i - 1][j] + sp[i][j - 1] - sp[i - 1][j - 1] + v[i][j];
}
}
ans = -1.0;
for(int x = r; x <= n; x++) {
for(int y = c; y <= m; y++) {
int mx = 0;
for(int i = n + 1; i <= 2 * n; i++) {
for(int j = m + 1; j <= 2 * m; j++) {
if((sp[i][j] - sp[i - x][j] - sp[i][j - y] + sp[i - x][j - y]) > mx)
mx = (sp[i][j] - sp[i - x][j] - sp[i][j - y] + sp[i - x][j - y]);
}
}
long double X = 1.0 * mx / (x * y);
if(X > ans)
ans = X;
}
}
cout << fixed << setprecision(4) << ans;
return 0;
}
``````