#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
ll pref[501][501], n, m, a, b;
ll dist (ll x) {
return abs(x - a) + abs(x - b);
}
int main () {
ios::sync_with_stdio(0);
cin.tie(0);
cin >> n >> m >> a >> b;
if (a > b) swap(a, b);
for (int i = 1; i <= n; i++) {
for (int j = 1; j <= m; j++) {
cin >> pref[i][j]; pref[i][j] += pref[i - 1][j];
}
}
ll mn = 1e18;
for (int l = 1; l <= n; l++) {
for (int r = l; r <= n; r++) {
ll arr[m + 1] = {};
for (int j = 1; j <= m; j++) {
arr[j] = pref[r][j] - pref[l - 1][j];
arr[j] += arr[j - 1];
}
int ptr = 1;
for (int i = 1; i <= m; i++) {
while (arr[i] - arr[ptr] < a && ptr) ptr--;
mn = min(mn, dist(arr[i] - arr[ptr]));
if (ptr) mn = min(mn, dist(arr[i] - arr[ptr - 1]));
}
}
}
cout << mn << '\n';
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
0 ms |
348 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
0 ms |
348 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
0 ms |
348 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |