#include<iostream>
#include<cstdio>
#include<string>
#include<cstring>
#include<string.h>
#include<algorithm>
using namespace std;
const int maxn = 1000;
int mark[maxn];
int n, k, p, x, y;
int main(){
scanf("%d%d%d%d%d", &n, &k, &p, &x, &y);
int cursum = 0;
int aboveMedium = 0, equalMedium = 0, belowMedium = 0;
int i;
for( i = 0; i < k; ++i){
scanf("%d", mark + i);
cursum += mark[i];
aboveMedium += mark[i] > y ? 1 : 0;
equalMedium += mark[i] == y ? 1 : 0;
belowMedium += mark[i] < y ? 1 : 0;
}
int leftday = n - k;
int leftscore = x - cursum;
if(leftday > leftscore){
printf("-1\n");
return 0;
}
int half = n >> 1;
if(belowMedium > half){
printf("-1\n");
return 0;
}
//leftscore -= leftday; //gain at least one point everyday
int nextidx = k;
for(i = belowMedium; i < half; ++i){
leftscore -= 1;
mark[nextidx] = 1;
nextidx++;
}
i = nextidx;
for(; i < n; ++i){
if(leftscore >= y){
mark[i] = y;
leftscore -= y;
}
else{
printf("-1\n");
return 0;
}
}
printf("%d", mark[k]);
for(int i = k + 1; i < n; ++i){
printf(" %d", mark[i]);
}
printf("\n");
return 0;
}
finally AC code
WA Code:
#include<iostream>
#include<cstdio>
#include<string>
#include<cstring>
#include<string.h>
#include<algorithm>
using namespace std;
const int maxn = 1000;
int mark[maxn];
int n, k, p, x, y;
int main(){
scanf("%d%d%d%d%d", &n, &k, &p, &x, &y);
int cursum = 0;
int aboveMedium = 0, equalMedium = 0, belowMedium = 0;
for(int i = 0; i < k; ++i){
scanf("%d", mark + i);
cursum += mark[i];
aboveMedium = mark[i] > y ? 1 : 0;
equalMedium = mark[i] == y ? 1 : 0;
belowMedium = mark[i] < y ? 1 : 0;
}
int leftday = n - k;
int leftscore = x - cursum;
if(leftday > leftscore){
printf("-1\n");
return 0;
}
int half = n >> 1;
if(belowMedium > half){
printf("-1\n");
return 0;
}
leftscore -= leftday; //gain at least one point everyday
for(int i = k; i < n; ++i){
mark[i] = 1;
}
for(int i = k; i < n; ++i){
if(leftscore > 4){
mark[i] += 4;
leftscore -= 4;
}
else{
mark[i] += leftscore;
break;
}
aboveMedium = mark[i] > y ? 1 : 0;
equalMedium = mark[i] == y ? 1 : 0;
belowMedium = mark[i] < y ? 1 : 0;
}
if(belowMedium > half){
printf("-1\n");
return 0;
}
printf("%d", mark[k]);
for(int i = k + 1; i < n; ++i){
printf(" %d", mark[i]);
}
printf("\n");
return 0;
}
WA Analysis:
magic number 4 , misleaded by sample inputs.
WA Code:
#include<iostream>
#include<cstdio>
#include<string>
#include<cstring>
#include<string.h>
#include<algorithm>
using namespace std;
const int maxn = 1000;
int mark[maxn];
int n, k, p, x, y;
int main(){
scanf("%d%d%d%d%d", &n, &k, &p, &x, &y);
int cursum = 0;
int aboveMedium = 0, equalMedium = 0, belowMedium = 0;
for(int i = 0; i < k; ++i){
scanf("%d", mark + i);
cursum += mark[i];
aboveMedium += mark[i] > y ? 1 : 0;
equalMedium += mark[i] == y ? 1 : 0;
belowMedium += mark[i] < y ? 1 : 0;
}
int leftday = n - k;
int leftscore = x - cursum;
if(leftday > leftscore){
printf("-1\n");
return 0;
}
int half = n >> 1;
if(belowMedium > half){
printf("-1\n");
return 0;
}
leftscore -= leftday; //gain at least one point everyday
for(int i = k; i < n; ++i){
mark[i] = 1;
}
for(int i = k; i < n; ++i){
if(leftscore > p - 1){
mark[i] += p - 1;
leftscore -= p - 1;
}
else if(leftscore > 0){
mark[i] += leftscore;
leftscore = 0;
}
aboveMedium += mark[i] > y ? 1 : 0;
equalMedium += mark[i] == y ? 1 : 0;
belowMedium += mark[i] < y ? 1 : 0;
}
if(belowMedium > half){
printf("-1\n");
return 0;
}
printf("%d", mark[k]);
for(int i = k + 1; i < n; ++i){
printf(" %d", mark[i]);
}
printf("\n");
return 0;
}
WA Analysis: doesn’t keep medium nature.