-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathPIE - pie spoj.cpp
48 lines (43 loc) · 1.32 KB
/
PIE - pie spoj.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
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
#define fast ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0);
ll n,f;
std::vector<ll> v;
bool possible(double size){
ll totalCake=0;
for(int i=0; i<n; i++){
totalCake+=((v[i]*v[i])*M_PI)/size;
}
return totalCake>=f;
}
int main(){
fast;
#ifndef ONLINE_JUDGE
freopen("inputf.in","r",stdin);
freopen("outputf.out","w",stdout);
#endif
//////////////////////////////////
int t;
cin>>t;
while(t--){
if(!v.empty())v.clear();
cin>>n>>f;
f++;
ll temp=n;
ll input;
while(temp--){
cin>>input;
v.push_back(input);
}
sort(v.rbegin(), v.rend());
double maxV=(v[0]*v[0])*M_PI;
double low=0, high=maxV, mid;
while(high-low>=1e-4){
mid=(high+low)/2;
if(possible(mid))low=mid;
else high=mid;
}
possible(high)?cout<<fixed<<setprecision(4)<<high<<"\n":cout<<fixed<<setprecision(4)<<low<<"\n";
}
return 0;}