#include<bits/stdc++.h>
using namespace std;
int r, s, a, b, c[501][501];
long long pref[501][501], ans;
inline long long get_sm(int x1, int x2, int y1, int y2){
long long res = pref[x2][y2] - pref[x1][y2] - pref[x2][y1] + pref[x1][y1];
if(x1!=x2||y1!=y2) ans = min(ans, abs(a - res) + abs(b - res));
return res;
}
signed main(){
ios_base::sync_with_stdio(0), cin.tie(0);
cin >> r >> s >> a >> b;
if(a>b) swap(a, b);
for(register int i = 1; i <= r; ++i){
for(register int j = 1; j <= s; ++j){
cin >> c[i][j];
ans += c[i][j];
pref[i][j] = pref[i-1][j] + pref[i][j-1] - pref[i-1][j-1] + c[i][j];
}
}
int xl(0), yl(0), xr(1), yr(1);
long long cur = get_sm(xl, xr, yl, yr);
while(xr <= r && yr <= s){
if(cur <= b){
long long y = get_sm(xl, xr, yr, yr + 1);
long long x = get_sm(xr, xr + 1, yl, yr);
if(x > y && yr < r){
++yr;
}else{
++xr;
}
}else{
long long y = get_sm(xl, xr, yl, yl + 1);
long long x = get_sm(xl, xl + 1, yl, yr);
if(x > y){
++yl;
}else{
++xl;
}
}
cur = get_sm(xl, xr, yl, yr);
}
cout << ans << '\n';
}
Compilation message
Main.cpp: In function 'int main()':
Main.cpp:18:19: warning: ISO C++17 does not allow 'register' storage class specifier [-Wregister]
18 | for(register int i = 1; i <= r; ++i){
| ^
Main.cpp:19:20: warning: ISO C++17 does not allow 'register' storage class specifier [-Wregister]
19 | for(register int j = 1; j <= s; ++j){
| ^
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
1 ms |
2396 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
1 ms |
2396 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
1 ms |
2396 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |