Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <bits/stdc++.h>
- using namespace std;
- const long long INF=2e18;
- vector <vector<long long>> qs(1001,vector<long long>(1001,0));
- int main(){
- int n,h,w;
- long long mx=-INF;
- scanf("%d%d%d",&n,&h,&w);
- for(int i=1;i<=n;i++){
- scanf("%lld",&qs[i][0]);
- }
- for(int i=1;i<=n;i++){
- scanf("%lld",&qs[0][i]);
- }
- for(int i=1;i<=n;i++){
- for(int j=1;j<=n;j++){
- if(i==1&&j==1) qs[i][j] = qs[i][0]+qs[0][j];
- else if(i==1) qs[i][j] = (qs[i][0]+qs[0][j]) + qs[i][j-1];
- else if(j==1) qs[i][j] = (qs[i][0]+qs[0][j]) + qs[i-1][j];
- else qs[i][j] = (qs[i][0]+qs[0][j]) + qs[i-1][j] + qs[i][j-1] - qs[i-1][j-1];
- if(i>=h && j>=w){
- if(i-h<=0 && j-w<=0) mx=max(mx, qs[i][j]);
- else if(i-h<=0) mx=max(mx, qs[i][j] - qs[i][j-w] );
- else if(j-w<=0) mx=max(mx, qs[i][j] - qs[i-h][j] );
- else mx = max(mx, qs[i][j] - qs[i-h][j] - qs[i][j-w] + qs[i-h][j-w] );
- }
- }
- }
- printf("%lld",mx);
- return 0;
- }
Add Comment
Please, Sign In to add comment