当前位置:网站首页>codeforces:C. Maximum Subrectangle【前缀和 + 贪心 + 最小子数组和】
codeforces:C. Maximum Subrectangle【前缀和 + 贪心 + 最小子数组和】
2022-08-03 19:51:00 【白速龙王的回眸】

分析
两个sigma的求和最终等价于
a的子数组和乘b的子数组和 小于等于 x
对于固定长度的子数组而言,我们都能找出一个和最小的
对于a和b我们都找出指定长度L和最小的子数组和(贪心)
然后一一配对,看看是否面积更大且满足和乘积小于等于x即可
ac code
import sys
import math
from itertools import accumulate
input = sys.stdin.readline
n, m = list(map(int, input().split()))
a = list(map(int, input().split()))
b = list(map(int, input().split()))
x = int(input())
# (aj1 + ... + aj2) * (bi1 + ... + bi2) <= x
ans = 0
# for a, b; fix length L, the min Sum => greedy
f1 = [math.inf] * (n + 1)
f2 = [math.inf] * (m + 1)
preSum1 = list(accumulate(a, initial = 0))
preSum2 = list(accumulate(b, initial = 0))
# for a
for l in range(1, n + 1):
for st in range(n - l + 1):
end = st + l - 1
f1[l] = min(f1[l], preSum1[end + 1] - preSum1[st])
# for b
for l in range(1, m + 1):
for st in range(m - l + 1):
end = st + l - 1
f2[l] = min(f2[l], preSum2[end + 1] - preSum2[st])
# combine
for l1, v1 in enumerate(f1):
for l2, v2 in enumerate(f2):
if l1 * l2 > ans and v1 * v2 <= x:
ans = l1 * l2
print(ans)
总结
转化为两个子数组的乘积
长度是两个未知数,枚举出来
然后选出当长度固定时最小的和即可
这个用前缀和稍微操作即可
边栏推荐
- 怎么将自己新文章自动推送给自己的粉丝(巨简单,学不会来打我)
- JS 内置构造函数 扩展 prototype 继承 借用构造函数 组合式 原型式creat 寄生式 寄生组合式 call apply instanceof
- Detailed AST abstract syntax tree
- The addition and subtraction of the score of the force deduction brush question (a daily question 7/27)
- 基础软件与开发语言开源论坛| ChinaOSC
- Detailed steps for tensorflow-gpu2.4.1 installation and configuration
- Postgresql source code (64) Query execution - data structure and execution process before submodule Executor (2) execution
- 【leetcode】剑指 Offer II 009. 乘积小于 K 的子数组(滑动窗口、双指针)
- 【leetcode】剑指 Offer II 008. 和大于等于 target 的最短子数组(滑动窗口,双指针)
- MySQL基础
猜你喜欢
随机推荐
消除对特权账户的依赖使用Kaniko构建镜像
建模该从哪一步开始?给你分析,给零基础的你一些学习建议
高性能计算软件与开源生态| ChinaOSC
「学习笔记」高斯消元
JMeter笔记5 |Badboy使用和录制
List类的超详细解析!(超2w+字)
JS 内置构造函数 扩展 prototype 继承 借用构造函数 组合式 原型式creat 寄生式 寄生组合式 call apply instanceof
MySQL 主从,6 分钟带你掌握!
安装radondb mysql遇到问题
X86函数调用模型分析
剑指 Offer II 044. 二叉树每层的最大值-dfs法
149. The largest number on a straight line, and check the set
微导纳米IPO过会:年营收4.28亿 君联与高瓴是股东
危化企业双重预防机制数字化建设进入全面实施阶段
嵌入式分享合集27
Detailed demonstration pytorch framework implementations old photo repair (GPU)
小马智行起诉擎天智卡:索赔6000万 彭军称要斗争到底
力扣刷题之移动零
不知道这4种缓存模式,敢说懂缓存吗?
ADS 2023 Download Link









