Codeforces Round #382 (Div. 2), problem: (B) Urbanization Solution in C/C++

#include<stdio.h>
#include<stdlib.h>
int cmp(const void*a,const void*b)
{
return *(int*)b-*(int*)a;
}
int w[100005];
int main()
{
	int n,n1,n2;
	scanf("%d%d%d",&n,&n1,&n2);
	for(int i=0;i<n;i++)
	scanf("%d",&w[i]);
	qsort(w,n,sizeof(w[0]),cmp);
	if(n1>n2)
	{
		int t=n1;
		n1=n2;
		n2=t;
	}
	double count1=0,count2=0;
	for(int i=0;i<n1;i++) 
	{
		count1+=1.0*w[i];
	}
	for(int i=n1;i<n1+n2;i++)
	{
		count2+=1.0*w[i];
	}
	printf("%.8lf\n",count1/n1+count2/n2);
	return 0;
}
(Visited 56 times, 1 visits today)

About the Author:

Taniv Ashraf

Leave A Comment