URAL 2015. Zhenya moves from the dormitory

来源:互联网 发布:开通淘宝网店多少费用 编辑:程序博客网 时间:2024/05/07 02:52

2015. Zhenya moves from the dormitory

Time limit: 1.0 second
Memory limit: 64 MB
After moving from his parents’ place Zhenya has been living in the University dormitory for a month. However, he got pretty tired of the curfew time and queues to the shower room so he took a fancy for renting an apartment. It turned out not the easiest thing in the world to make a choice. One can live in a one bedroom apartment or in a two bedroom apartment, alone or share it with a friend. Zhenya can afford to rent an apartment of any type alone, but he can share only a two bedroom apartment. If two people share an apartment, each pays half of the rent. Every apartment has its own advantages like part of the town, floor, view from the windows, etc., which Zhenya is going to take into account to make a decision.
Besides that, his friends, he’s ready to share an apartment with, also have certain advantages. For example, Igor is a good cook,Dima is tidy, Kostya is a good cook and at the same time can explain how to solve functional analysis problems. And do not forget that living alone has its own bright sides.
Zhenya has already prepared the list of suitable apartments and possible housemates. Zhenya has estimated in units the advantages of each apartment and each friend and also the advantages of living alone. Besides, he knows the maximum sum of money he and each of his friends is ready to pay for the apartment. Help Zhenya to make a decision.

Input

The first line contains three integers: the maximum sum Zhenya is ready to pay monthly, the advantages of living alone in a one bedroom apartment and the advantages of living alone in a two bedroom apartment.
The second line contains an integer n that is the number of Zhenya’s friends (0 ≤n ≤ 256). Next n lines describe the friends, two integers in every line: the maximum sum the corresponding friend is ready to pay monthly and the advantages of sharing an apartment with him.
The next line contains an integer m that is the number of suitable apartments (1 ≤m ≤ 256). Next m lines describe the apartments, three integers in every line: the number of bedrooms in an apartment (1 or 2), monthly rent and the advantages of living there.
All the advantages are estimated in the same units and lie in the range from 0 to 100 000. All sums of money are in rubles and lie in the range from 1 to 100 000.

Output

Output the variant with maximum sum of advantages, Zhenya (and his friend in case of sharing apartments) can afford. If Zhenya should rent an apartment numberi alone, output “You should rent the apartment #i alone.”. If he should share an apartment numberi with a friend j output “You should rent the apartment #i with the friend #j.”. Friends and apartments are numbered from 1 in order they are given in the input. If there are several optimal alternatives, output any of them. If Zhenya can’t afford to rent any apartment at all, output “Forget about apartments. Live in the dormitory.”.

Samples

inputoutput
10000 50 70110000 10021 10000 2002 30000 500
You should rent the apartment #1 alone.
30000 0 1110000 100131 20000 20002 30000 20002 10000 1001
You should rent the apartment #3 with the friend #1.
1000 0 0011 10000 1000
Forget about apartments. Live in the dormitory.

Notes

In the first example Zhenya can’t afford even to share the second apartment. That is why he has to rent the first one. The sum of advantages in this case will be 250 (50 + 200).
In the second example Zhenya can afford any apartment but he can share only the third one. If he chooses this variant, the sum of advantages will be 2002 (1001 + 1001), and if he chooses to live alone it will not be more than 2001 (1 + 2000 in case of living alone in the second apartment).
In the third example Zhenya can’t afford the only possible variant.
Problem Author: Eugene Kurpilyansky

Problem Source: NEERC 2014, Eastern subregional contest

这代码敲得我自己都得加注释。。。

开始写的很麻烦 彻底分成了三种

比赛时改了两个半小时也没改出来= =

改后用ans存所有情况下的优点最多的

然后全用t存屋子的号

#include<bits/stdc++.h>struct node{    int peo;    int pri,adv;   //int sad11 ,sad12,sad22;//sad11 1   sad22 2zhu2   sad12} x[300];struct nodefri{    int num;    int mon;    int adv;} z[300];int main(){    int i,j;    int m,n;    int a,b,money;    scanf("%d%d%d",&money,&a,&b);    scanf("%d",&n);    for(i=0; i<n; i++) //n朋友的个数   m屋子数    {        scanf("%d%d",&z[i].mon,&z[i].adv);        z[i].num=i+1;    }//z是朋友    scanf("%d",&m);    for(i=0; i<m; i++)    {        scanf("%d%d%d",&x[i].peo,&x[i].pri,&x[i].adv);        x[i].sad11=0,x[i].sad12=0,x[i].sad22=0;    }    int f=0;    int ans=-1,t=-1;    for(i=0; i<m; i++)    {        if(x[i].peo==1)        {            if(money>=x[i].pri)            {                f=1;                if(ans<x[i].adv+a)                {                    ans=x[i].adv+a;                    t=i+1;                }            }        }        else        {            if(money>=x[i].pri)            {                f=1;                if(ans<x[i].adv+b)                {                    ans=x[i].adv+b;                    t=i+1;                }            }        }    }    int f22=-1;    for(i=0; i<n; i++) //朋友    {        for(j=0; j<m; j++) //双人间        {            if(x[j].peo==2)            {                if(money>=((x[j].pri*1.0)/2)&&z[i].mon>=((x[j].pri*1.0)/2))                {                    if(x[j].adv+z[i].adv>ans)                    {                        f=2;                        ans=x[j].adv+z[i].adv;                        f22=i+1;                        t=j+1;                    }                }            }        }    }    if(f==0) printf("Forget about apartments. Live in the dormitory.\n");    else    {        if(f==1)        {            printf("You should rent the apartment #%d alone.\n",t);        }        else//            (ma22>=ma11&&ma22>=ma12)        {            printf("You should rent the apartment #%d with the friend #%d.\n",t,f22);        }    }    return 0;}


0 0
原创粉丝点击