fork download
  1. #include <iostream>
  2. #include <algorithm>
  3.  
  4. #define fname "."
  5. #define ll long long
  6.  
  7. using namespace std;
  8. int n, m, w, h;
  9. ll a[100005], b[100005];
  10.  
  11. int main() {
  12. if(fopen(fname"inp", "r")) {
  13. freopen(fname"inp", "r", stdin);
  14. freopen(fname"out", "w", stdout);
  15. }
  16. cin>>n>>m>>w>>h;
  17. for(int i=1; i<=n; ++i) cin>>a[i], a[i]+=a[i-1];
  18. for(int i=1; i<=m; ++i) cin>>b[i], b[i]+=b[i-1];
  19.  
  20. ll mxa=-1e18, mxb=-1e18;
  21.  
  22. ll res=-1e18;
  23. if(w<=n && h<=m) {
  24. for(int i=w; i<=n; ++i) mxa=max(mxa, a[i]-a[i-w]);
  25. for(int i=h; i<=m; ++i) mxb=max(mxb, b[i]-b[i-w]);
  26. res=max(res, w*mxa+h*mxb);
  27. }
  28. if(h<=n && w<=m) {
  29. mxa=-1e18, mxb=-1e18;
  30. for(int i=h; i<=n; ++i) mxa=max(mxa, a[i]-a[i-w]);
  31. for(int i=w; i<=m; ++i) mxb=max(mxb, b[i]-b[i-w]);
  32. res=max(res, h*mxa+w*mxb);
  33. }
  34. cout<<res;
  35. }
  36. /*
  37.  
  38. */
Success #stdin #stdout 0s 5320KB
stdin
Standard input is empty
stdout
Standard output is empty