Http://codeforces.com/contest/1060/problem/C
The and only and n,m sequences in the rectangle are related to the difference in the above. For example, the and 7,8,9 cross-formed and = (1+2+3) * (7+8+9) = 144.
The crossover of two is the choice of the difference, without mutual influence.
So, the strategy is that we first find a goal sequence for the sequence n n_sum[],n_sum[i] that records all of the contiguous lengths of I in N, and the minimum is what. For example: n=[3,4,2,2], then n_sum=[0,2,4,8,11], where the number of subscript 3 is 8, which represents the smallest and 8 in the continuous subsequence of the n medium length 3.
How to get behind the explanation, first to have this n_sum and m_sum as a precondition. Note that the values in the two series are incremented.
With N_sum and m_sum,n_sum each subscript i, find m_sum[j]*n_sum[i]<x on the line. Since the values in the two series are incremented, the position is recorded with the double pointer, which can be done using O (n). This is equal to the possibility of all lengths matching. Every time you find it, use Ans=max (ANS,I*J).
As for how to find the smallest sum of each length, first copy the contents of N to temp, first look for length 1, equals min (n), and then each time temp[i]=n[i]+temp[i+1] increments the length. This is O (n^2) complexity.
Python too slow, with C + + rewrite again, spent a half-small debug problem unexpectedly is on the burst int, hey ~
int is 32bit Max 10^10
Python version:
N, m = [Int (x) forXinchinput (). Split ()]ns= [Int (x) forXinchinput (). Split ()]ms= [Int (x) forXinchinput (). Split ()]k=int (input ())defGetlen (arr): ans=[0] Start=arr[:] ans.append (min (arr)) forLinchRange (2, Len (arr) + 1): Minn= 10**16 forIinchRange (len (arr)-L + 1): Start[i]= Arr[i] + start[i + 1] Minn=min (Minn, start[i]) ans.append (Minn)returnANSNL=Getlen (NS) ML=Getlen (MS) J=0ans=0 forIinchReversed (Range (n+1)): whileJ<m+1 andml[j]*nl[i]<=k:j+=1ans=max (ans,i* (j-1))Print(ANS)
View Code
C + + version:
#include <iostream>#include<vector>#include<cstring>#include<algorithm>using namespacestd;#definell Long LongVector<ll> Getlen (ll*a,ll L) {Vector<ll>ans; Ans.push_back (0); ll Start[l]; memcpy (Start, A, L*sizeof(ll)); LL Minn=Int_max; for(LL i =0; i<l;i++) Minn=min (minn,start[i]); Ans.push_back (Minn); for(LL k=2; k<=l;k++) {Minn=Int_max; for(LL i=0; i<=l-k;i++) {Start[i]=a[i]+start[i+1]; Minn=min (minn,start[i]); } ans.push_back (Minn); } returnans;}intMainintargcChar**argv) {ll n,m; CIN>>n>>m; ll Ns[n]; ll Ms[m]; for(LL i=0; i<n;i++) {cin>>Ns[i]; } for(LL i=0; i<m;i++) {cin>>Ms[i]; } ll K; CIN>>K; Vector<ll> nl=Getlen (ns,n); Vector<ll> ml=Getlen (ms,m); ll ans=0; LL J=1; for(LL i=n;i>0; i--){ while(j<m+1&& ml[j]*nl[i]<=k) J + +; Ans=max (ans,i* (J-1)); } cout<<ans; return 0;}
CF Maximum Subrectangle