540B - School Marks - CodeForces Solution


greedy implementation *1700

Please click on ads to support us..

C++ Code:

#include<iostream>
#include<algorithm>
#include<cstring>
using namespace std;
int a[1000],b[1000];
int ans=0;
int main()
{
	int n,k,p,x,y,i,sum=0,summ=0;
	cin>>n>>k>>p>>x>>y;
	for(i=1;i<=k;i++)
	{
		cin>>a[i];
		sum+=a[i];
	}
	sort(a+1,a+k+1);
	for(i=1;i<=k;i++)
	{
		if(a[i]<y)
		{
			ans++;
		}
	}
	if(ans<(n+1)/2)
	{
		for(i=k+1;i<=n;i++)
	   {
		    a[i]=1;
		    b[i]=a[i];
	   }
	   for(i=k+n/2-ans+1;i<=n;i++)
	   {
	    	a[i]=y;
		    b[i]=a[i];
       }
	}
	else
	    a[i]=-1;
	for(i=1;i<=n;i++)
	{
		summ+=a[i];
	}
	sort(a+1,a+n+1);
	if(a[n/2+1]<y||summ>x)
	    cout<<"-1"<<endl;
	else
	{
		for(i=k+1;i<n;i++)
		{
			cout<<b[i]<<" ";
		}
		cout<<b[n]<<endl;
	}
	return 0;
} 
    		 	 	  	 		 		   						


Comments

Submit
0 Comments
More Questions

519C - A and B and Team Training
631A - Interview
961B - Lecture Sleep
522A - Reposts
1166D - Cute Sequences
1176A - Divide it
1527A - And Then There Were K
1618E - Singers' Tour
1560B - Who's Opposite
182B - Vasya's Calendar
934A - A Compatible Pair
1618F - Reverse
1684C - Column Swapping
57C - Array
1713D - Tournament Countdown
33A - What is for dinner
810A - Straight A
1433C - Dominant Piranha
633A - Ebony and Ivory
1196A - Three Piles of Candies
299A - Ksusha and Array
448B - Suffix Structures
1092B - Teams Forming
1166C - A Tale of Two Lands
544B - Sea and Islands
152B - Steps
1174D - Ehab and the Expected XOR Problem
1511A - Review Site
1316A - Grade Allocation
838A - Binary Blocks