$$mid \leq \frac {\sum v _ i}{\sum c _ i}$$

$$\sum v _ i – mid \sum c _ i \geq 0$$

#include <bits/stdc++.h>

#define NS (3000)
#define MS (120000)
#define H(a, b) (((a) - 1) * (m + 1) + b)

using namespace std;

template<typename _Tp> inline void IN(_Tp &dig)
{
char c; bool flag = 0; dig = 0;
while (c = getchar(), !isdigit(c)) if (c == '-') flag = 1;
while (isdigit(c)) dig = dig * 10 + c - '0', c = getchar();
if (flag) dig = -dig;
}

int n, m, N, sum[55][55];

struct graph
{
int head[NS], nxt[MS], to[MS], x[MS], y[MS], sz;
double w[MS];
void refresh(double z)
{
for (int i = 0; i < sz; i += 1) w[i] = y[i] - z * x[i];
}
void push(int a, int b, int c, int d)
{
nxt[sz] = head[a], to[sz] = b, x[sz] = c, y[sz] = d, head[a] = sz++;
}
} g;

double dis[NS];

bool book[NS];

int cnt[NS];

deque<int> que;

bool chk(double x)
{
g.refresh(x), fill(dis + 1, dis + 1 + N, -1e9);
memset(book + 1, 0, sizeof(bool) * N);
memset(cnt + 1, 0, sizeof(int) * N);
que.clear(), que.push_back(1);
dis[1] = 0, cnt[1] = book[1] = 1;
while (!que.empty())
{
int F = que[0]; que.pop_front(), book[F] = 0;
for (int i = g.head[F]; ~i; i = g.nxt[i])
if (dis[g[i]] < dis[F] + g.w[i])
{
dis[g[i]] = dis[F] + g.w[i];
if (!book[g[i]])
{
if (que.empty() || dis[g[i]] < dis[que[0]])
que.push_back(g[i]);
else que.push_front(g[i]);
book[g[i]] = 1;
if (++cnt[g[i]] >= N - 1) return 1;
}
}
}
return 0;
}

int main(int argc, char const* argv[])
{
IN(n), IN(m), N = (n + 1) * (m + 1);
for (int i = 1; i <= n; i += 1)
for (int j = 1, a; j <= m; j += 1)
IN(a), sum[i][j] = sum[i][j - 1] + a;
for (int i = 1; i <= n + 1; i += 1)
for (int j = 1, a; j <= m; j += 1)
{
IN(a);
g.push(H(i, j), H(i, j + 1), a, 0);
g.push(H(i, j + 1), H(i, j), a, 0);
}
for (int i = 1; i <= n; i += 1)
for (int j = 1, a; j <= m + 1; j += 1)
{
IN(a);
g.push(H(i, j), H(i + 1, j), a, -sum[i][j - 1]);
g.push(H(i + 1, j), H(i, j), a, sum[i][j - 1]);
}
double l = 0, r = 1250, mid;
while (r - l > 1e-5)
{
mid = (l + r) * 0.5;
if (chk(mid)) l = mid;
else r = mid;
}
printf("%.3f\n", l);
return 0;
}


#### Remmina

No puzzle that couldn't be solved.