➤ Problem Link : PIE
👉 Hint : edit please
✅ C++ Solution :
#include<bits/stdc++.h>
using namespace std;
#define _USE_MATH_DEFINES
bool fun(double arr[],double val,int n,int f)
{
if(val==0)
return false;
int k=0;
for(int i=0;i<n;i++)
{
double x=arr[i];
k+=(int)(x/val);
if(k>=f)
{
return true;
}
}
return false;
}
int main()
{
ios_base::sync_with_stdio(false);
cin.tie(NULL);
int t,n,f;
cin>>t;
while(t--)
{
double max=0.0;
cin>>n>>f;
double arr[n];
for(int i=0;i<n;i++)
{
cin>>arr[i];
arr[i]=acos(-1)*arr[i]*arr[i];
if(arr[i]>max)
max=arr[i];
}
double low=0.0,high=max,mid;
int k=100;
while(k--)
{
mid=(low+high)/2;
if(fun(arr,mid,n,f+1)) //1 extra for myself
low=mid;
else
high=mid;
}
printf("%.4f\n",high);
}
return 0;
}
Thank you for your patience reading. If you enjoyed this post, I’d be very grateful if you’d help it spread by emailing it to a friend, or sharing it on Whatsapp or Facebook.
😇Happy Learning!!
