CF1060C.Maximum Subrectangle
普及/提高-
通过率:0%
AC君温馨提醒
该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。
题目描述
You are given two arrays a and b of positive integers, with length n and m respectively.
Let c be an n×m matrix, where ci,j=ai⋅bj .
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 x1,x2,y1,y2 subject to 1≤x1≤x2≤n , 1≤y1≤y2≤m , (x2−x1+1)×(y2−y1+1)=s , and $$∑i=x1x2∑j=y1y2ci,j≤x. $$
输入格式
The first line contains two integers n and m ( 1≤n,m≤2000 ).
The second line contains n integers a1,a2,…,an ( 1≤ai≤2000 ).
The third line contains m integers b1,b2,…,bm ( 1≤bi≤2000 ).
The fourth line contains a single integer x ( 1≤x≤2⋅109 ).
输出格式
If it is possible to choose four integers x1,x2,y1,y2 such that 1≤x1≤x2≤n , 1≤y1≤y2≤m , and ∑i=x1x2∑j=y1y2ci,j≤x , output the largest value of (x2−x1+1)×(y2−y1+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):