#BS0000415. Cân bằng lượng nước giữa các thùng (Pour Water Between Buckets to Make Water Levels Equal)
Bài tập thuộc lộ trình
Mục lục đề ⌄
Cân bằng lượng nước giữa các thùng (Pour Water Between Buckets to Make Water Levels Equal)
Pour Water Between Buckets to Make Water Levels Equal
Source: LeetCode
Version: Phuoc Hung OJ Extended
Problem Statement
There are buckets numbered 1 through . Bucket initially holds gallons. You may transfer any amount of water, including a noninteger amount, between two distinct buckets, provided the source has enough water. A transfer of gallons loses gallons; the destination receives the rest. Equalize all bucket amounts and maximize their common amount.
Input
The first line contains integers , the bucket count and percentage loss. The second line contains integers , the initial water amounts in gallons.
Output
Print the maximum common amount in gallons. Absolute error must not exceed .
Subtasks
- Subtask 1 (20 points): ; for every ; .
- Subtask 2 (30 points): ; for every ; .
- Subtask 3 (50 points): ; for every ; .
Examples
Input
3 80
1 2 7
Output
2.000000000000
Explanation
Transfer 5 gallons from bucket 3 to bucket 1; 4 gallons are lost and 1 arrives. Each bucket now holds 2 gallons. A higher common amount requires more than 1 gallon for the first two buckets, but the last bucket has less than 5 gallons of surplus and can deliver less than 1 gallon.
Input
3 50
2 4 6
Output
3.500000000000
Explanation
Transfer 0.5 and 2.5 gallons from buckets 2 and 3 to bucket 1. It receives 0.25 and 1.25 gallons, reaching 3.5; the other two retain 3.5 each. A higher level leaves less than 3 gallons of surplus, delivering less than 1.5 gallons, insufficient for bucket 1.
Input
4 40
3 3 3 3
Output
3.000000000000
Explanation
All four buckets already contain 3 gallons, so no transfer is needed. The initial total is 12 gallons and transfers cannot increase it. Hence the common amount cannot exceed .