# Cod sursa(job #2453037)

Utilizator Data 2 septembrie 2019 11:39:23 Balans 60 cpp-64 done Arhiva de probleme 1.9 kb
``````#include <cstdio>

using namespace std;

const int NMAX = 153;

int N, M, L, C;

long long A[2 * NMAX][2 * NMAX];

long long ansa, ansb;

bool Ok = 0;

static inline long long Sum (int x1, int y1, int x2, int y2)
{
return A[x2][y2] - A[x2][y1 - 1] - (A[x1 - 1][y2] - A[x1 - 1][y1 - 1]);
}

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

scanf("%d%d%d%d", &N, &M, &L, &C);

for(int i = 1; i <= N; ++i)
for(int j = 1; j <= M; ++j)
scanf("%d", &A[i][j]);

for(int i = 1; i < N; ++i)
for(int j = 1; j < M; ++j)
A[i][j + M] = A[i + N][j] = A[i + N][j + M] = A[i][j];

for(int i = 1; i < 2 * N; ++i)
for(int j = 1; j < 2 * M; ++j)
A[i][j] += A[i - 1][j] + A[i][j - 1] - A[i - 1][j - 1];

for(int l = L; l <= N; ++l)
for(int c = C; c <= M; ++c)
for(int l1 = 1, l2 = l; l1 <= N; ++l1, ++l2)
for(int c1 = 1, c2 = c; c1 <= M; ++c1, ++c2)
{
long long Numa = Sum(l1, c1, l2, c2);
long long Numb = l * c;

if(!Ok)
{
ansa = Numa;
ansb = Numb;

Ok = 1;

continue;
}

if(1LL * Numa * ansb > 1LL * Numb * ansa)
{
ansa = Numa;

ansb = Numb;
}
}

long double p1 = ansa;
long double p2 = ansb;

long double ans = (long double)(p1 / p2);

long long V = (long long)(ans * 1000.0);

long long Nr = V % (1LL * 1000);

int d1 = Nr / 100;
int d2 = (Nr % 100) / 10;
int d3 = Nr % 10;

printf("%lld.%d%d%d\n", V / (1LL * 1000), d1, d2, d3);

return 0;
}
``````