【Codeforces Round #301 (Div. 2) B】 School Marks
【链接】 我是链接,点我呀:)
【题意】
【题解】
首先判断k门成绩的和是不是小于等于x. 然后x-sum就是剩下的n-k个数字最多能填的和。 可以这样。 既然中位数要大于等于y; 那么转化为让(n+1)/2个数字都大于等于p; 则在剩下的n-k个位置凑足(n+1)/2个p就够了。 凑够了就都用1填就好。【代码】
#include <bits/stdc++.h>
using namespace std;
const int N = 1e3;
int n,k,p,x,y;
int a[N+10];
vector <int> v;
void wujie(){
puts("-1");
exit(0);
}
void buqi(int pos,int rest){
for (int i = pos;i <= n;i++){
v.push_back(1);
rest--;
if (rest<0) wujie();
}
}
int main(){
#ifdef LOCAL_DEFINE
freopen("rush_in.txt", "rt", stdin);
#endif
scanf("%d%d%d%d%d",&n,&k,&p,&x,&y);
for (int i = 1;i <= k;i++) scanf("%d",&a[i]);
int sum1 = 0;
for (int i = 1;i <= k;i++) sum1+=a[i];
if (sum1 > x) wujie();
int rest = x - sum1;
if (rest < (n-k)) wujie();
int num = 0;
for (int i = 1;i <= k;i++)
if (a[i]>=y) num++;
if (num>=(n+1)/2)
buqi(k+1,rest);
else{
int need = (n+1)/2 - num;
int i;
bool flag = true;
for (i = k+1;i <= n;i++){
if (rest>=y){
v.push_back(y);
rest-=y;
need--;
if (need==0) break;
}else{
flag = false;
break;
}
}
if (flag && need==0){
if (i+1<=n) buqi(i+1,rest);
}else wujie();
}
for (int i = 0,first = 1;i < (int) v.size();i++){
if (!first) putchar(' ');
first = 0;
printf("%d",v[i]);
}
return 0;
}