当前位置:网站首页>Codeforce:g. good key, bad key [greed]
Codeforce:g. good key, bad key [greed]
2022-07-19 13:25:00 【White speed Dragon King's review】

analysis
There are two operations , We don't know which one to choose
Let's consider a after b And first b after 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
therefore ,bad Back root good All bad
therefore bad Continue the root later bad, most 30 individual , The back is full of 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)
summary
Found out bad Cannot root behind good It's done greedily
边栏推荐
- jvm自学总结
- [Yugong series] July 2022 go teaching course 012 forced type conversion
- Possible problems in inserting Excel data into MySQL database
- XML建模(简单易学)
- VMware导入ova/ovf虚拟机文件
- 实现自动记录日志
- Force buckle 64 minimum path sum -- Introduction to dynamic programming
- 稳超胜算,历9弥新 | 2022金仓创新产品发布会顺利召开
- Brief analysis of circuit fault
- 最小交換次數
猜你喜欢

Advanced C language -- custom type: structure enumeration Union

Uio-66 | fe3o4/cu3 (BTC) 2 metal organic framework (MOF) nanocomposites supported on silver nanoparticles | nagdf4:yb, er upconversion nanoparticles @zif-8

Azkaban 安装文档

jvm自学总结
[email protected] (FE) composite nan"/>Metal organic framework material / polymer composite zif-8/p (TDA co HDA) | zinc oxide [email protected] (FE) composite nan

国产API工具哪家强?原来是它…

Unveiling secrets of matrixcube 101 - functions and architecture of matrixcube

C语言进阶——自定义类型:结构体 枚举 联合
![[pyGame learning notes] 6 Cursor mouse cursor](/img/ea/70fb3043ae32eca68e31144a54b651.jpg)
[pyGame learning notes] 6 Cursor mouse cursor

动手学深度学习(第二版)注释后代码【持续更新】
随机推荐
【错误记录/selectpicker】dropdown menu显示位置出现偏移
Lanthanide metal organic skeleton( [email protected] )|Rhodamine 6G modified MOF material | catalase @zif composite | MOF
Visual ETL tool kettle concept, installation and practical cases
Qiyue supplies cumof nanocrystals loaded with methylene blue | femof nanosheets grown in situ on foam nickel | oxide nanowires /zif MOFs sugar gourd like Composites
Realize automatic logging
(PC+WAP)织梦模板服装礼服类网站
Ossimport migration path
[error record /selectpicker] the display position of dropdown menu is offset
Label ball problem
Equivalent domain name
MatrixCube揭秘 101——MatrixCube的功能与架构
Advanced C language -- custom type: structure enumeration Union
Minimum exchange times
LeetCode 0117. 填充每个节点的下一个右侧节点指针 II
音频控制常见BUG注意事项
Wrong again, byte alignment and the use of pragma pack
Nitrogen heterocyclic molecule modified uio-66-nh2 | polyethyleneimine modified uio-66-nh2| [email protected] @Zif67 nanomaterial
Interviewer: is it acceptable to transfer to go?
可视化ETL工具Kettle概念、安装及实战案例
力扣70-爬楼梯——动态规划