A12097 | Maximum Subrectangle
时间限制1s
内存限制256MB
通过 / 提交0/0
题目描述
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.$ $$
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.$ $$
输入格式
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}$ ).
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}$ ).
输出格式
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$ .
输入输出样例
输入 #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):

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

C++ 编辑器
输入
输出
可保存默认模板;新题优先使用已保存模板。
当前快捷键仅展示,暂不支持修改。
- 撤销
Ctrl / ⌘ + Z - 重做
Ctrl / ⌘ + Y - 查找
Ctrl / ⌘ + F - 全选
Ctrl / ⌘ + A - 复制
Ctrl / ⌘ + C - 剪切
Ctrl / ⌘ + X - 粘贴
Ctrl / ⌘ + V - 自动排版
工具栏排版按钮 - 草稿保存
编辑时自动保存到本机
历史
提交记录
状态说明时间源码
AI
作答助手
你好,我是作答助手。可以问思路、复杂度、样例含义或代码报错原因;不会直接给出完整 AC 代码。
确定要清空代码吗?
提交通过
评测结果:Accepted