比赛 |
20101117 |
评测结果 |
WWWWWWWWWW |
题目名称 |
物品 |
最终得分 |
0 |
用户昵称 |
wangwangdog |
运行时间 |
0.000 s |
代码语言 |
C++ |
内存使用 |
0.00 MiB |
提交时间 |
2010-11-17 11:27:07 |
显示代码纯文本
#include<stdio.h>
#include<string>
long i,j,flag,num[1001],n,pi,mon[1001],mon1[1001],mon2[1001],all,l,putong[1001],mofa[1001],fl[1001];
char cc[100];
int main()
{
FILE *fin,*fout;
fin=fopen("magica.in","rb");
fout=fopen("magica.out","wb");
fscanf(fin,"%ld%ld\n",&n,&pi);
for(i=1;i<=n;i++)
{
fscanf(fin,"%s\n",&cc[1]);
l=strlen(&cc[1]);
flag=1;
num[i]=1;
if(cc[1]!=' ')
{
for(j=1;j<=l;j++)
{
if(cc[j]==' ')flag=0;
if(flag==0&&cc[j]!=' ')num[i]=2;
}
}
else
{
long pp=1;
while(cc[pp]==' ')pp++;
for(j=pp;j<=l;j++)
{
if(cc[j]==' ')flag=0;
if(flag==0&&cc[j]!=' ')num[i]=2;
}
}
}
fclose(fin);
fin=fopen("magica.in","rb");
fscanf(fin,"%ld%ld\n",&n,&pi);
for(i=1;i<=n;i++)
{
if(num[i]==1)fscanf(fin,"%ld\n",&mon[i]);
if(num[i]==2)fscanf(fin,"%ld%ld\n",&mon1[i],&mon2[i]);
}
long money=0;
long pa=0,pb=0;
for(i=1;i<=n;i++)
{
if(num[i]==1){pa++;putong[pa]=i;}
if(num[i]==2){pb++;mofa[pb]=i;}
}
for(i=1;i<=pa;i++)
money=money+mon[putong[i]];
all=pb;
for(i=1;i<=pb;i++)
fl[i]=1;
for(i=1;i<=pb;i++)
{
if(mon2[mofa[i]]-pi<=mon1[mofa[i]])
{
fl[i]=0;
money=money+mon1[mofa[i]];
all--;
}
}
while(all!=0)
{
if(money>=pi)
{
long max=0,maxp=0;
for(i=1;i<=pb;i++)
if(mon2[mofa[i]]-pi>max&&fl[i]!=0)
{
maxp=i;
max=mon2[mofa[i]]-pi;
}
fl[maxp]=0;
money=money+max;
all--;
}
else
{
long min=30000,minp=1;
for(i=1;i<=pb;i++)
if(fl[i]==1&&money+mon1[mofa[i]]>=pi&&mon1[mofa[i]]<min)
{
min=mon2[mofa[i]]-pi;
minp=i;
}
money=money+min;
all--;
fl[minp]=0;
}
}
fprintf(fout,"%ld",money);
fclose(fin);
fclose(fout);
return 0;
}