It is known that an array of length n and an array B of length m are asked to satisfy the maximum area where all the numbers in a sub-matrix are added less than x when the two are multiplied to form a matrix.
Mathematical problems, This problem can be converted to find a sub-array from A and B, so that the sum of the elements of these sub-arrays is less than or equal to X, and the product of their size is the largest
#include <bits/stdc++.h>#definell Long Longusing namespacestd;Const intmaxn= -+Ten; ll A[maxn],b[maxn],minsa[maxn],minsb[maxn];ll n,m,x;intMain () {Ios::sync_with_stdio (false); Cin.tie (0); CIN>>n>>m; for(intI=0; i<n;i++) {cin>>A[i]; } for(intI=0; i<m;i++) {cin>>B[i]; } CIN>>x; for(intI=0; i<maxn;i++) Minsa[i]=minsb[i]=x+1; for(intI=0; i<n;i++) {ll sum=0; for(intj=i;j<n;j++) {sum+=A[j]; Minsa[j-i+1]=min (minsa[j-i+1],sum); } } for(intI=0; i<m;i++) {ll sum=0; for(intj=i;j<m;j++) {sum+=B[j]; Minsb[j-i+1]=min (minsb[j-i+1],sum); } } intans=0; for(intI=1; i<=n;i++) { for(intj=1; j<=m;j++){ if(minsa[i]*minsb[j]<=x) Ans=max (ans,i*j); }} cout<<ans<<Endl; return 0;}
Codeforces Round #513 c-maximum subrectangle (math + thinking)