http://codeforces.com/problemset/problem/540/B
题意
有一个人,需要考n科,已经考了k科,他需要他的n科分数和不大于x,中位数不小于y
然后让你构造出一个可行解
题解:
把剩下的n-k科全部置为y,如果不行,就置为1
#include <iostream>
#include <cmath>
#include <cstring>
#include <algorithm>
#include <queue>
#include <cstdio>
using namespace std;
#define N 1310
#define INF 0x3f3f3f3f
#define met(a, b) memset (a, b, sizeof (a))
int main ()
{
int n, k, p, x, y, val1[N], val2[N];
while (scanf ("%d%d%d%d%d", &n, &k, &p, &x, &y) != EOF)
{
int sum = 0;
met (val1, 0);
met (val2, 0);
for (int i=1; i<=k; i++)
{
scanf ("%d", &val1[i]);
sum += val1[i];
}
int m = n-k, j = 0;
while (m)
{
if (sum+y<=x && x-(sum+y)>=m-1)
{
val1[++k] = y;
val2[j++] = y;
sum += y;
}
else
{
val1[++k] = 1;
val2[j++] = 1;
sum++;
}
m--;
}
sort (val1+1, val1+n+1);
if (val1[(n+1)/2]<y || sum>x)
{
puts ("-1");
continue;
}
for (int i=0; i<j-1; i++)
printf ("%d ", val2[i]);
printf ("%d\n", val2[j-1]);
}
return 0;
}