Advertisement
Guest User

UCL Game Night

a guest
Jul 21st, 2019
108
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.42 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3.  
  4. const int N = 110;
  5.  
  6. int t;
  7. int n,m,k;
  8. int grid[N][N];
  9. int sum[N];
  10.  
  11. int slidingWindow(int j,int curd)
  12. {
  13.     int l=0,r=0,s=0;
  14.     int mxSummation = -1;
  15.     int mxSummationL = -1, mxSummationR = -1;
  16.     while(l<n)
  17.     {
  18.         while(r<n&& s+sum[r]<=k) s+=sum[r],r++;
  19.         if(mxSummation<s)
  20.         {
  21.             mxSummation = s;
  22.             mxSummationL = l;
  23.             mxSummationR = r;
  24.         }
  25.         s-=sum[l];
  26.         l++;
  27.     }
  28.    // cout << mxSummationL << " " << mxSummationR << endl << curd << " " << j << endl;
  29.     return (mxSummationR-mxSummationL)*(j-curd+1);
  30. }
  31.  
  32. int main()
  33. {
  34.     ios::sync_with_stdio(0);
  35.     cin.tie(NULL);
  36.     cout.tie(NULL);
  37.  
  38.     #ifndef ONLINE_JUDGE
  39.         //freopen("input.txt", "r", stdin);
  40.         //freopen("out.txt", "w", stdout);
  41.     #endif // ONLINE_JUDGE
  42.  
  43.     cin >> t;
  44.     while(t--)
  45.     {
  46.         int ans = 0;
  47.         cin >> n >> m >> k;
  48.         for(int i = 0; i < n; i++)
  49.             for(int j = 0; j < m; j++)
  50.                 cin >> grid[i][j];
  51.         for(int d = 0; d < n; d++)
  52.         {
  53.             memset(sum,0,sizeof sum);
  54.             for(int j = d; j<m; j++)
  55.             {
  56.                 for(int i = 0; i < n; i++)
  57.                     sum[i]+=grid[i][j];
  58.                 ans = max(ans,slidingWindow(j,d));
  59.             }
  60.         }
  61.         cout << ans << endl;
  62.     }
  63.  
  64.     return 0;
  65. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement