Codeforces Round 513 by Barcelona Bootcamp (rated, Div. 1 + Div. 2)
C
Maximum Subrectangle
Codeforces
1600
原题
← BD →
翻译中…

You are given two arrays $a$ and $b$ of positive integers, with length $n$ and $m$ respectively.

翻译中…

Let $c$ be an $n \times m$ matrix, where $c_{i,j} = a_i \cdot b_j$.

翻译中…

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

翻译中…

Formally, you need to find the largest number $s$ such that it is possible to choose integers $x_1, x_2, y_1, y_2$ subject to $1 \leq x_1 \leq x_2 \leq n$, $1 \leq y_1 \leq y_2 \leq m$, $(x_2 - x_1 + 1) \times (y_2 - y_1 + 1) = s$, and $$\sum_{i=x_1}^{x_2}{\sum_{j=y_1}^{y_2}{c_{i,j}}} \leq x.$$

翻译中…

Input

翻译中…

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

翻译中…

The second line contains $n$ integers $a_1, a_2, \ldots, a_n$ ($1 \leq a_i \leq 2000$).

翻译中…

The third line contains $m$ integers $b_1, b_2, \ldots, b_m$ ($1 \leq b_i \leq 2000$).

翻译中…

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

翻译中…

Output

翻译中…

If it is possible to choose four integers $x_1, x_2, y_1, y_2$ such that $1 \leq x_1 \leq x_2 \leq n$, $1 \leq y_1 \leq y_2 \leq m$, and $\sum_{i=x_1}^{x_2}{\sum_{j=y_1}^{y_2}{c_{i,j}}} \leq x$, output the largest value of $(x_2 - x_1 + 1) \times (y_2 - y_1 + 1)$ among all such quadruplets, otherwise output $0$.

翻译中…

Note

翻译中…

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

翻译中…

image

翻译中…

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

翻译中…

image

翻译中…

样例

Input #1
3 3
1 2 3
1 2 3
9
Output #1
4
InputCopy OutputCopy
Input #2
5 1
5 4 2 4 5
2
5
Output #2
1
InputCopy OutputCopy
题目信息
题号
1060C
时间限制
2 s
内存限制
512 MB
标签
二分
模拟
双指针

题面与样例版权归 Codeforces 及出题人所有;中文翻译由 AI 生成(CI 管线),如有出入请以原文为准。