当前位置:网站首页>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
边栏推荐
- MySQL advanced (13) command line export import database
- Performance analysis method - Notes on top of performance
- Computing network, AI first, shengteng AI helps operators' Digital Transformation -- work together to win-win Computing Era
- Peripherals: interrupt system of keys and CPU
- Scientific data center resources and user access control system
- Contemporary fairy quotations
- [summer daily question] Luogu p1706 full ranking question
- Harbor installation
- Beijing Zhun electric clock, Beidou clock server, GPS network time server, NTP satellite timing system
- Why is the exclude or include attribute setting of the < keep alive > component invalid
猜你喜欢

Summary of the most complete MySQL data types in history (Part 2)

An article explains unsupervised learning in images in detail

How to obtain workers' coats and helmets in stray? How to obtain workers' helmets

Harbor installation

Deep understanding of string class

Chinese son-in-law OTA Ono became the first Asian president of the University of Michigan, with an annual salary of more than 6.5 million!

Detailed explanation of the principles and differences between static pages and dynamic pages

Musk responded whether he would upload his brain to the cloud: already did it!
Windows Server 2022 received a non security update in July: fix the sticking problem caused by defender

6-10 vulnerability exploitation SMTP experimental environment construction
随机推荐
G025-db-gs-ins-02 openeuler deployment opengauss (1 active and 1 standby)
Mobile Robotics (3) Kalman filter
In the post deep learning era, where is the recommendation system going?
Remove & lt; li> Front blank distance
Today in history: the kotlin language was published for the first time; The father of the IMAP agreement was born; CT imaging achieves a new breakthrough
【Power Shell】Invoke-Expression ,Invoke-Expression -Command $activateCommand; Error or power shell failed to activate the virtual environment
PG Optimization -- execution plan
Chinese son-in-law OTA Ono became the first Asian president of the University of Michigan, with an annual salary of more than 6.5 million!
Automatically create partition tables by time and month in PostgreSQL
Using multithreaded execution method in Lua script based on nlua implementation
Thinkphp5.0.24 deserialization chain analysis
Management mode of agricultural science data center based on life cycle theory
Take C language from 0 to 1 - program structure and use examples
When executing SQL query statements in MySQL database, the underlying implementation principle (ultra detailed)
1260. Two dimensional grid migration: simple construction simulation problem
Cloud native platform, let edge applications play out!
[daily question in summer] Luogu p6850 Noi
Take the first place in the International Olympic Games in mathematics, physics and chemistry, and win all the gold medals. Netizen: the Chinese team is too good
What are the important trends revealed by the release of "operator data viability index"?
Safety management and application of genomic scientific data