题意:有n个数,先给出p个数,现在要求另外n-p个数,使得这n个数的中位数大于等于y,并且n个数之和不大于x。没有方案就输出⑴.
代码:
#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <cmath>
#include <string>
#include <map>
#include <stack>
#include <vector>
#include <set>
#include <queue>
#pragma comment (linker,"/STACK:102400000,102400000")
#define maxn 1005
#define MAXN 2005
#define mod 1000000009
#define INF 0x3f3f3f3f
#define pi acos(⑴.0)
#define eps 1e⑹
#define lson rt<<1,l,mid
#define rson rt<<1|1,mid+1,r
#define FRE(i,a,b) for(i = a; i <= b; i++)
#define FREE(i,a,b) for(i = a; i >= b; i--)
#define FRL(i,a,b) for(i = a; i < b; i++)
#define FRLL(i,a,b) for(i = a; i > b; i--)
#define mem(t, v) memset ((t) , v, sizeof(t))
#define sf(n) scanf("%d", &n)
#define sff(a,b) scanf("%d %d", &a, &b)
#define sfff(a,b,c) scanf("%d %d %d", &a, &b, &c)
#define pf printf
#define DBG pf("Hi
")
typedef long long ll;
using namespace std;
int n,p,k,x,y;
int a[maxn];
int ans[maxn];
int main()
{
// freopen("C:/Users/asus1/Desktop/IN.txt","r",stdin);
int i,j;
while (~scanf("%d%d%d%d%d",&n,&p,&k,&x,&y))
{
int s=0,l=0,r=0,num=0,cnt=0;
for (i=0;i<p;i++)
{
scanf("%d",&a[i]);
s+=a[i];
if (a[i]<y) l++; //记录比y小的数有多少
else if (a[i]>=y) r++;//记录大于等于y的数有多少
}
if (l>=n/2+1){ //如果比y小的数超过了1半,那末中位数不可能到达y了
printf("⑴
");
continue;
}
int xx=n/2+1-r;
while (xx>0){ //填充右侧,尽可能填y使得和最小
ans[cnt++]=y;
xx--;s+=y;
}
xx=n-r-l-cnt;
while (xx>0) //填充左侧,填1使和尽可能小
{
ans[cnt++]=1;
xx--;s++;
}
if (s>x){ //和超过x输出⑴
printf("⑴
");
continue;
}
printf("%d",ans[0]);
for (i=1;i<cnt;i++)
printf(" %d",ans[i]);
printf("
");
}
return 0;
}