Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<bits/stdc++.h>
- using namespace std;
- #define ll int
- #define pb push_back
- #define fr first
- #define sc second
- #define ARRS int(2e5+11)
- #define MTXS int(1e3+11)
- #define INF int(2e12+11)
- ll i,j,k,p,l,m,n,r,f,A,B,C,D;
- ll a[MTXS][MTXS],sm[MTXS][MTXS],lg[MTXS][MTXS],s[MTXS][MTXS],mm[MTXS][MTXS];
- deque<pair<ll,ll> > dk;
- int main(){
- #ifdef KHOKHO
- freopen("in.in","r",stdin);
- freopen("out.out","w+",stdout);
- #endif
- cin>>m>>n>>D>>C>>B>>A;
- for(int i=1; i<=n; i++){
- for(int j=1; j<=m; j++){
- cin>>a[i][j];
- }
- }
- for(int i=1; i<=n; i++){
- for(int j=1; j<=m; j++){
- s[i][j]=s[i-1][j]+s[i][j-1]-s[i-1][j-1]+a[i][j];
- }
- }
- for(int i=1; i<=n-A; i++){
- for(int j=1; j<=m-B; j++){
- sm[i][j]=s[i+A][j+B]-s[i+A][j]-s[i][j+B]+s[i][j];
- cout<<sm[i][j]<<" ";
- }
- cout<<endl;
- }
- for(int i=1; i<=n-C; i++){
- for(int j=1; j<=m-D; j++){
- lg[i][j]=s[i+C][j+D]-s[i+C][j]-s[i][j+D]+s[i][j];
- }
- }
- ll pas;
- for(int i=1; i<=n-C; i++){
- for(int j=1; j<=m-D; j++){
- ll k = sm[i+1][j+1];
- while(!dk.empty()&&k<=dk.back().second){
- dk.pop_back();
- }
- dk.push_back({j,k});
- while(!dk.empty()&&dk.front().first<=j+1)
- dk.pop_back();
- mm[i][j]=dk.front().second;
- }
- }
- dk.clear();
- for(int i=1; i<=m-D; i++){
- for(int j=1; j<=n-C; j++){
- ll k = mm[j+1][i+1];
- while(!dk.empty()&&k<=dk.back().second){
- dk.pop_back();
- }
- dk.push_back({j,k});
- while(!dk.empty()&&dk.front().first<=j+1)
- dk.pop_back();
- cout<<lg[j][i]<<endl;
- pas=min(pas,lg[j][i]-dk.front().second);
- }
- }
- cout<<pas;
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement