当前位置:网站首页>codeforce:G. Good Key, Bad Key【贪心】
codeforce:G. Good Key, Bad Key【贪心】
2022-07-17 18:13:00 【白速龙王的回眸】
分析
有两个操作,我们不知道选哪个
我们就考虑先a后b和先b后a
# x y
# good and bad: x + y // 2 - k
# bad and good: x // 2 + y // 2 - k
# thus, after bad no good
# 2 ^ 30 > 10 ** 9, at most 30 bad
因此,bad后面根good都是不好的
所以bad后面继续根bad,最多30个,后面全0
ac code
import sys
input = sys.stdin.readline
for _ in range(int(input())):
n, k = list(map(int, input().split()))
a = list(map(int, input().split()))
# x y
# good and bad: x + y // 2 - k
# bad and good: x // 2 + y // 2 - k
# thus, after bad no good
# 2 ^ 30 > 10 ** 9, at most 30 bad
maxn = 0
nowSum = 0
for i in range(n):
badSum = nowSum
cnt = 0
while cnt < 32 and i + cnt < n:
badSum += a[i + cnt] // (2 ** (cnt + 1))
cnt += 1
maxn = max(maxn, badSum)
nowSum += a[i] - k # goodSum
maxn = max(maxn, nowSum)
print(maxn)
总结
发现了bad后面不能根good就贪心搞定了
边栏推荐
- MatrixCube揭秘 101——MatrixCube的功能与架构
- XML文件解析
- AE如何制作星云粒子特效
- Advanced C language -- custom type: structure enumeration Union
- Nitrogen heterocyclic molecule modified uio-66-nh2 | polyethyleneimine modified uio-66-nh2| [email protected] @Zif67 nanomaterial
- 【js逆向爬虫】-有道翻译js逆向实战
- Visual ETL tool kettle concept, installation and practical cases
- npm err! [email protected] build: `umi build`
- 力扣198-213 打家劫舍Ⅰ、Ⅱ——动态规划
- XML建模(简单易学)
猜你喜欢
LeetCode 0118. 杨辉三角
torch. utils. data. Dataloader description
How to upgrade Flink job gracefully?
Amino metal organic framework material Fe MOF, fe-mil-88nh2 | Zr based metal organic framework catalyst (pt-uio-66) | Qiyue biology
Label ball problem
模块7(王者荣耀商城异地多活架构设计)
Differences between get requests and post requests and usage examples
Azkaban 安装文档
C语言进阶——字符函数和字符串函数
sqli-labs(less-11)
随机推荐
时序逻辑与组合逻辑的reg
506. Relative ranking
LeetCode 0117. Populate the next right node pointer II of each node
Array simulation queue
Equivalent domain name
MySQL advanced (VI) introduction to four common uses of fuzzy query
XML文件解析
Security measures for tcp/ip protocol vulnerabilities
Azkaban installation documentation
标签球问题
音频控制常见BUG注意事项
力扣413-等差数列划分——动态规划
Unveiling secrets of matrixcube 101 - functions and architecture of matrixcube
[pyGame learning notes] 5 Collision detection of rect objects
mysql排序索引失效?
(PC+WAP)织梦模板服装礼服类网站
【Try to Hack】arp和arp欺骗
If you merge cells by Excel, export excelutils
Can you view MySQL data table structure in two ways?
Audio common terminal anatomy - never make a mistake again