// - Art -
#include <bits/stdc++.h>
#define el cout << '\n'
#define int long long
#define FOR(i, a, b) for (int i = (a), _b = (b); i <= _b; ++i)
#define REV(i, b, a) for (int i = (b), _a = (a); i >= _a; --i)
#define REP(i, c) for (int i = 0, _c = (c); i < _c; ++i)
const int N = 5e2 + 7;
template <class T1, class T2>
bool maximize(T1 &a, T2 b){
if (a < b) {a = b; return true;}
return false;
}
template <class T1, class T2>
bool minimize(T1 &a, T2 b){
if (a > b) {a = b; return true;}
return false;
}
using namespace std;
int a[N][N];
long long sum[N], pre[N];
main() {
ios_base::sync_with_stdio(false);
cin.tie(0); cout.tie(0);
int m, n, A, B;
cin >> m >> n >> A >> B;
if (A > B) {
swap(A, B);
}
long long res = 1e18;
FOR (i, 1, m) FOR (j, 1, n) {
cin >> a[i][j];
}
FOR (x1, 1, m) {
FOR (i, 1, n) {
sum[i] = 0;
pre[i] = 0;
}
FOR (x2, x1, m) {
int idx1 = 0, idx2 = 0;
FOR (i, 1, n) {
sum[i] += a[x2][i];
pre[i] = pre[i - 1] + 2 * sum[i];
while (pre[i] - pre[idx1] >= A + B) {
minimize(res, (pre[i] - pre[idx1]) - (A + B));
++idx1;
}
minimize(res, (A + B) - (pre[i] - pre[idx1 - 1]));
while (pre[i] - pre[idx2] >= A * 2) {
if (pre[i] - pre[idx2] <= B * 2) {
minimize(res, B - A);
}
++idx2;
}
}
}
}
cout << res, el;
return 0;
}
Compilation message (stderr)
Main.cpp:31:2: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
31 | main() {
| ^~~~
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |