链接http://acm.timus.ru/problem.aspx?space=1&num=2015
#include<stdio.h>
#include<string.h>
#include<stdlib.h>
struct Friend
{
double mo;
int ad;
}f[300];
struct house
{
double mo;
int ad;
int ds;
}h[300];
int main()
{
int i,j,n1,n2,m,flag=0,ad[5],t_f,t_h,t_ad=-1;
double mo_m;
scanf("%lf%d%d",&mo_m,&ad[1],&ad[2]);
scanf("%d",&n1);
for(i=1;i<=n1;i++)
{
scanf("%lf%d",&f[i].mo,&f[i].ad);
}
scanf("%d",&n2);
for(i=1;i<=n2;i++)
{
scanf("%d%lf%d",&h[i].ds,&h[i].mo,&h[i].ad);
}
for(i=1;i<=n2;i++)
{
if(h[i].mo<=mo_m&&t_ad<ad[h[i].ds]+h[i].ad)
{
t_h=i;
t_ad=ad[h[i].ds]+h[i].ad;
flag=1;
}
if(h[i].ds==1) continue;
if(h[i].mo/2.0>mo_m) continue;
for(j=1;j<=n1;j++)
{
if(h[i].mo/2.0<=f[j].mo&&t_ad<h[i].ad+f[j].ad)
{
t_h=i;
t_ad=h[i].ad+f[j].ad;
t_f=j;
flag=2;
}
}
}
if(flag==0) printf("Forget about apartments. Live in the dormitory.\n");
else if(flag==1) printf("You should rent the apartment #%d alone.\n",t_h);
else if(flag==2) printf("You should rent the apartment #%d with the friend #%d.\n",t_h,t_f);
return 0;
}