比赛 |
20101118 |
评测结果 |
WAAAAAAWWA |
题目名称 |
分班 |
最终得分 |
70 |
用户昵称 |
wangwangdog |
运行时间 |
0.000 s |
代码语言 |
C++ |
内存使用 |
0.00 MiB |
提交时间 |
2010-11-18 11:05:48 |
显示代码纯文本
#include<stdio.h>
FILE *fin,*fout;
long num[51],n,i,xia,shang;
int main()
{
fin=fopen("groupa.in","rb");
fout=fopen("groupa.out","wb");
fscanf(fin,"%ld\n",&n);
for(i=1;i<=n;i++)
fscanf(fin,"%ld",&num[i]);
fscanf(fin,"\n");
fscanf(fin,"%ld%ld",&xia,&shang);
long budao=0,chaole=0,jushang=0,juxia=0;
for(i=1;i<=n;i++)
{
if(num[i]<xia)budao=budao+xia-num[i];
if(num[i]>shang)chaole=chaole+num[i]-shang;
if(num[i]<=shang&&num[i]>=xia){jushang=jushang+shang-num[i];juxia=juxia+num[i]-xia;}
}
if(chaole==budao)fprintf(fout,"%ld",budao);
if(chaole<budao)
{
if(chaole+juxia+shang-xia<budao)fprintf(fout,"-1");
else fprintf(fout,"%ld",budao);
}
if(chaole>budao)
{
if(jushang+budao+shang-xia<chaole)fprintf(fout,"-1");
else fprintf(fout,"%ld",chaole);
}
fclose(fin);
fclose(fout);
return 0;
}