#include <bits/stdc++.h>
using namespace std;
int main(){
int r, s, a, b; cin >> r >> s >> a >> b;
int v[r][s]; for(int i = 0; i < r; i++) for(int j = 0; j < s; j++) cin >> v[i][j];
for(int i = 1; i < r; i++) for(int j = 0; j < s; j++) v[i][j] += v[i - 1][j];
int ans = INT_MAX;
for(int i = 0; i < r; i++){
for(int j = i; j < r; j++){
int pos = 0, sum = 0;
for(int k = 0; k < s; k++){
sum += v[j][k] - v[i - 1][k];
while(sum > b && pos <= k){
ans = min(ans, abs(b - sum) + abs(sum - a));
sum -= v[j][pos] - v[i - 1][pos];
pos++;
}
if(a <= sum && b >= sum){
cout << b - a << '\n'; return 0;
}
ans = min(ans, abs(b - sum) + abs(sum - a));
}
}
}
cout << ans << '\n';
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
344 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
344 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
344 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |