CF1060C.Maximum Subrectangle

普及/提高-

通过率:0%

时间限制:2.00s

内存限制:512MB

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=ai⋅bjc_{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 1≤x1≤x2≤n1 \leq x_1 \leq x_2 \leq n, 1≤y1≤y2≤m1 \leq y_1 \leq y_2 \leq m, (x2−x1+1)×(y2−y1+1)=s(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.$$

给你两个正整数数组 aa 和 bb,长度分别为 nn 和 mm。

令 cc 是一个 n×mn \times m 的矩阵,其中 ci,j=ai⋅bjc_{i,j} = a_i \cdot b_j。

你需要在矩阵 cc 中找出一个子矩形,使其所有元素之和不超过 xx,且其面积(即所含元素的总数)尽可能大。

形式化地说,你需要找出最大的整数 ss,使得存在满足以下条件的整数 x1,x2,y1,y2x_1, x_2, y_1, y_2:
1≤x1≤x2≤n1 \leq x_1 \leq x_2 \leq n,
1≤y1≤y2≤m1 \leq y_1 \leq y_2 \leq m,
(x2−x1+1)×(y2−y1+1)=s(x_2 - x_1 + 1) \times (y_2 - y_1 + 1) = s,
且

∑i=x1x2∑j=y1y2ci,j≤x.\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 (1≤n,m≤20001 \leq n, m \leq 2000).

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

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

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

第一行包含两个整数 nn 和 mm(1≤n,m≤20001 \leq n, m \leq 2000)。

第二行包含 nn 个整数 a1,a2,…,ana_1, a_2, \ldots, a_n(1≤ai≤20001 \leq a_i \leq 2000)。

第三行包含 mm 个整数 b1,b2,…,bmb_1, b_2, \ldots, b_m(1≤bi≤20001 \leq b_i \leq 2000)。

第四行包含一个整数 xx(1≤x≤2⋅1091 \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 1≤x1≤x2≤n1 \leq x_1 \leq x_2 \leq n, 1≤y1≤y2≤m1 \leq y_1 \leq y_2 \leq m, and ∑i=x1x2∑j=y1y2ci,j≤x\sum_{i=x_1}^{x_2}{\sum_{j=y_1}^{y_2}{c_{i,j}}} \leq x, output the largest value of (x2−x1+1)×(y2−y1+1)(x_2 - x_1 + 1) \times (y_2 - y_1 + 1) among all such quadruplets, otherwise output 00.

如果存在四个整数 x1,x2,y1,y2x_1, x_2, y_1, y_2,满足 1≤x1≤x2≤n1 \leq x_1 \leq x_2 \leq n、1≤y1≤y2≤m1 \leq y_1 \leq y_2 \leq m,且 ∑i=x1x2∑j=y1y2ci,j≤x\sum_{i=x_1}^{x_2}{\sum_{j=y_1}^{y_2}{c_{i,j}}} \leq x,则输出所有满足条件的四元组中 (x2−x1+1)×(y2−y1+1)(x_2 - x_1 + 1) \times (y_2 - y_1 + 1) 的最大值;否则输出 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):

第一个样例的矩阵以及所选的子矩形(蓝色):

第二个样例的矩阵以及所选的子矩形(蓝色):

输入解题思路,AI测评打分。不知道怎么写?

首页