当前位置:网站首页>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就贪心搞定了
边栏推荐
- OSSImport迁移之路
- 【刷题记录】13. 罗马数字转整数
- O & M LITTLE WHITE Growth record - architecture week 6
- What are the pain points of collaborative tools collaborative office management
- Uio-66 - (COOH) 2 modified polyamide nanofiltration membrane | zif-8/pvp composite nanofiber membrane | uio-66-nh2 modified polyamide nanofiltration membrane
- 面试官:可以接受转Go吗?
- Basic database operations in MySQL
- 【Pygame 学习笔记】7.事件
- Mycat2 builds MySQL master-slave separation
- In depth sorting: summary of machine learning modeling and parameter adjustment methods
猜你喜欢
[email protected] )|Rhodamine 6G modified MOF material | catalase @zif composite | MOF"/>Lanthanide metal organic skeleton( [email protected] )|Rhodamine 6G modified MOF material | catalase @zif composite | MOF

LeetCode 0117. Populate the next right node pointer II of each node
![[pyGame learning notes] 6 Cursor mouse cursor](/img/ea/70fb3043ae32eca68e31144a54b651.jpg)
[pyGame learning notes] 6 Cursor mouse cursor

Uio-66 | fe3o4/cu3 (BTC) 2 metal organic framework (MOF) nanocomposites supported on silver nanoparticles | nagdf4:yb, er upconversion nanoparticles @zif-8
![[record of question brushing] 13 Roman numeral to integer](/img/44/9eff513ff8eb4109d3f77ed6832ee8.png)
[record of question brushing] 13 Roman numeral to integer

Basic database operations in MySQL
![[Yugong series] July 2022 go teaching course 012 forced type conversion](/img/7d/79f3e3e9fc73ee860b9607b7ebbb84.png)
[Yugong series] July 2022 go teaching course 012 forced type conversion

【错误记录/selectpicker】dropdown menu显示位置出现偏移
![Code after annotation of hands-on deep learning (Second Edition) [continuous update]](/img/4a/726a2103817aa4bdb86d1d8eeabce9.jpg)
Code after annotation of hands-on deep learning (Second Edition) [continuous update]

Array simulation queue
随机推荐
565.数组嵌套
标签球问题
Cadmium sulfide supported mil-125 (TI) | streptavidin (SA) - zirconium porphyrin MOF composite (PCN- [email protected] )|Shell core
Unveiling secrets of matrixcube 101 - functions and architecture of matrixcube
弘业期货网上开户安全吗?有没有开户指引?
【Pygame 学习笔记】7.事件
动手学深度学习(第二版)注释后代码【持续更新】
STL string复制比较
[pyGame learning notes] 5 Collision detection of rect objects
协同工具协同办公的管理具有哪些痛点
Flask源码分析(三):上下文
Nombre minimal d'échanges
Flask source code analysis (III): Context
Which domestic API tool is better? It turned out to be it
El table column drag and drop (no need to introduce other plug-ins)
Uio-66 | fe3o4/cu3 (BTC) 2 metal organic framework (MOF) nanocomposites supported on silver nanoparticles | nagdf4:yb, er upconversion nanoparticles @zif-8
MYCAT divides the database and table according to the hash value of the string range
【错误记录/selectpicker】dropdown menu显示位置出现偏移
面试难题:分布式 Session 实现难点,这篇就够!
Audio common terminal anatomy - never make a mistake again