CF1060C.Maximum Subrectangle

普及/提高-

通过率:0%

AC君温馨提醒

该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。

题目描述

You are given two arrays aa and bb of positive integers, with length nn and mm respectively.

Let cc be an n×mn \times m matrix, where ci,j=aibjc_{i,j} = a_i \cdot b_j .

You need to find a subrectangle of the matrix cc such that the sum of its elements is at most xx , and its area (the total number of elements) is the largest possible.

Formally, you need to find the largest number ss such that it is possible to choose integers x1,x2,y1,y2x_1, x_2, y_1, y_2 subject to 1x1x2n1 \leq x_1 \leq x_2 \leq n , 1y1y2m1 \leq y_1 \leq y_2 \leq m , (x2x1+1)×(y2y1+1)=s(x_2 - x_1 + 1) \times (y_2 - y_1 + 1) = s , and $$i=x1x2j=y1y2ci,jx.\sum_{i=x_1}^{x_2}{\sum_{j=y_1}^{y_2}{c_{i,j}}} \leq x. $$

输入格式

The first line contains two integers nn and mm ( 1n,m20001 \leq n, m \leq 2000 ).

The second line contains nn integers a1,a2,,ana_1, a_2, \ldots, a_n ( 1ai20001 \leq a_i \leq 2000 ).

The third line contains mm integers b1,b2,,bmb_1, b_2, \ldots, b_m ( 1bi20001 \leq b_i \leq 2000 ).

The fourth line contains a single integer xx ( 1x21091 \leq x \leq 2 \cdot 10^{9} ).

输出格式

If it is possible to choose four integers x1,x2,y1,y2x_1, x_2, y_1, y_2 such that 1x1x2n1 \leq x_1 \leq x_2 \leq n , 1y1y2m1 \leq y_1 \leq y_2 \leq m , and i=x1x2j=y1y2ci,jx\sum_{i=x_1}^{x_2}{\sum_{j=y_1}^{y_2}{c_{i,j}}} \leq x , output the largest value of (x2x1+1)×(y2y1+1)(x_2 - x_1 + 1) \times (y_2 - y_1 + 1) among all such quadruplets, otherwise output 00 .

输入输出样例

  • 输入#1

    3 3
    1 2 3
    1 2 3
    9
    

    输出#1

    4
    
  • 输入#2

    5 1
    5 4 2 4 5
    2
    5
    

    输出#2

    1
    

说明/提示

Matrix from the first sample and the chosen subrectangle (of blue color):

Matrix from the second sample and the chosen subrectangle (of blue color):

首页