-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathB. Ropes codeforces.cpp
76 lines (62 loc) · 1.26 KB
/
B. Ropes codeforces.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
// B. Ropes
// time limit per test1 second
// memory limit per test256 megabytes
// inputstandard input
// outputstandard output
// There are n
// ropes, you need to cut k
// pieces of the same length from them. Find the maximum length of pieces you can get.
// Input
// The first line contains two integers n
// and k
// (1≤n,k≤10000
// ). Next n
// lines contain one number each, the length of the rope ai
// (1≤ai≤107
// ).
// Output
// Output one real number, maximum length of pieces you can get. The answer will be considered correct if the relative or absolute error does not exceed 10−6
// .
// Example
// inputCopy
// 4 11
// 802
// 743
// 457
// 539
// outputCopy
// 200.5
#include<bits/stdc++.h>
using namespace std;
bool ispossible(vector<double>&ropes,int k,int n,double mid){
long long x=0;
for(int i=0;i<n;i++){
x += floor(ropes[i] / mid);
if(x>=k){
return true;
}
}
return false;
}
int main(){
long long n,k;
cin>>n>>k;
double ans=-1;
vector<double>ropes(n);
for(int i=0;i<n;i++){
cin>>ropes[i];
}
double r = 1e7+1;
double l=0.0;
while(r-l>=1e-6){
double mid=l+(r-l)/2;
if(ispossible(ropes , k , n ,mid)){
ans=mid;
l=mid;
}
else{
r=mid;
}
}
cout << fixed << setprecision(20) << ans << endl;
}