当前位置:网站首页>Codeforces:d1. choosing carrots (easy version) [max min problem + control one side to make the other side as close as possible + thinking]
Codeforces:d1. choosing carrots (easy version) [max min problem + control one side to make the other side as close as possible + thinking]
2022-07-25 02:01:00 【White speed Dragon King's review】

analysis
Must let a Array divided by p After array
The value across is the smallest
We can traverse the minimum value , Then let each value close to the minimum value to complete greed
Obviously, the minimum value can be taken from [1,a[0]]
And then the others pi We can set it to pi = min(k, ai // vi) vi Is the current minimum
This means to let pi Take the maximum , Make it as close as possible vi Not more than k
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()))
# greedy
if k > a[-1]:
print(0)
continue
# try the minn
mincost = 0xffffffff
minn = a[0]
for i in range(1, minn + 1):
p = []
# make pi max to greedly get the min cost
for aa in a:
if i != 0:
p.append(min(k, aa // i))
else:
p.append(k)
q = [a[i] // p[i] for i in range(n)]
mincost = min(mincost, max(q) - min(q))
print(mincost)
summary
Worst value problem
thinking
Consider fixing one , Let the other as close as possible
This is the simplification of thinking
边栏推荐
- Opengauss kernel analysis: query rewriting
- [daily question in summer] Luogu p6850 Noi
- Mongodb security cluster construction
- I was forced to graduate by a big factory and recited the eight part essay in a two-month window. Fortunately, I went ashore, otherwise I wouldn't be able to repay the mortgage
- High performance memory recovery technology for decrypting ark -- HPP GC
- Several schemes of traffic exposure in kubernetes cluster
- PostgreSQL views tables, table indexes, views, table structures, and parameter settings
- Create thread: pthread_ create
- MySQL advanced (13) command line export import database
- CSRF attack principle scenario
猜你喜欢

Peripherals: interrupt system of keys and CPU
![[programmer interview classic] 01.09 string rotation](/img/d2/7ea9351c31af01665d86f8c6bc3468.png)
[programmer interview classic] 01.09 string rotation

Three modes of executing programs, memory and cache

Mobile Robotics (3) Kalman filter

Ireport export PDF font bold failure
10 commonly used data visualization tool software

"I gave up programming and wrote a 1.3 million word hard science fiction."

DotNetCore. Cap notes

The introduction of 23 Filipino doctors for 18million was a hot topic, and the school teacher responded: expedient

Multithreading and high concurrency (II) -- synchronized locking and unlocking process
随机推荐
JVM Foundation
The two supply chain centers of HEMA launched the "background" of innovative research and development of multi format commodities
Green low-carbon Tianyi cloud, a new engine of digital economy!
Ecosystem long-term observation data product system
Detailed explanation of MySQL, Oracle and PostgreSQL database index failure scenarios
Peripherals: timer, watchdog and RTC
6-11 vulnerability exploitation - use the built environment to send emails
How MySQL 8.0 based on TRX_ Id find the statement of the whole transaction
Synchronization primitive: lock
Dynamic memory development
What are the important trends revealed by the release of "operator data viability index"?
DotNetCore. Cap notes
C#/VB. Net insert watermark in word
【Appium】Failed to create session. An unknown server-side error occurred while processing the command
Kubernetes creates a user with dashboard read-only permission (with exec permission)
Anacona has too many environments?? How to view your current environment in jupyter
xts performance auto fix script
Why is the exclude or include attribute setting of the < keep alive > component invalid
[summer daily question] Luogu p1605 maze
Gbase 8s how to query relational databases in sentences to select sample syntax and results of data from complex types