https://www.codechef.com/problems/SIMPSTAT
In C++..........................
#include <bits/stdc++.h>
using namespace std;
int main()
{
int t,a,b,c;
cin>>t;
while(t--)
{
cin>>a>>b;
long long anf=0;
vector<long long>joy;
while(a--)
{
cin>>c;
anf=anf+c;
joy.push_back(c);
}
sort(joy.begin(),joy.end());
long long sum=0;
for(int j=0;j<=b-1;j++)
{
sum=sum+joy[j];
}
for(int j=joy.size()-1;j>=joy.size()-(b);j--)
{
sum=sum+joy[j];
}
double ans=(double)(anf-sum);
double l=(double)(joy.size()-(2*b));
printf("%.06lf\n",ans/l);
}
return 0;
}
In C++..........................
#include <bits/stdc++.h>
using namespace std;
int main()
{
int t,a,b,c;
cin>>t;
while(t--)
{
cin>>a>>b;
long long anf=0;
vector<long long>joy;
while(a--)
{
cin>>c;
anf=anf+c;
joy.push_back(c);
}
sort(joy.begin(),joy.end());
long long sum=0;
for(int j=0;j<=b-1;j++)
{
sum=sum+joy[j];
}
for(int j=joy.size()-1;j>=joy.size()-(b);j--)
{
sum=sum+joy[j];
}
double ans=(double)(anf-sum);
double l=(double)(joy.size()-(2*b));
printf("%.06lf\n",ans/l);
}
return 0;
}
No comments:
Post a Comment