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 number i alone, output “You should rent the apartment #i alone.”. If he should share an apartment number i 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.”.

Example

input output
10000 50 70
1
10000 100
2
1 10000 200
2 30000 500
You should rent the apartment #1 alone.
30000 0 1
1
10000 1001
3
1 20000 2000
2 30000 2000
2 10000 1001
You should rent the apartment #3 with the friend #1.
1000 0 0
0
1
1 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.

Hint

/*
* @Author: lyuc
* @Date: 2017-04-30 15:11:54
* @Last Modified by: lyuc
* @Last Modified time: 2017-04-30 15:32:17
*/
/**
* 题意:Zhenya想租房子,可以和朋友合租,也可以自己租,自己租的时候要付全部的租金,和朋友合租的时候要严格的
* 一人一半
*
* 思路:暴力,读错题了,应该是自己住的单间的时候快乐值是:快乐值1+酒店快乐值,自己住双人间的时候快乐值是:
* 快乐值2+酒店快乐值,和朋友合租的时候快乐值是:朋友的快乐值+酒店快乐值
*/
#include <iostream>
#include <stdio.h>
using namespace std;
struct Fr{
int pay,hap;
}fr[];
struct Ho{
int id,pay,hap;
}ho[];
int pay,hap1,hap2;
int n,m;
int main(){
// freopen("in.txt","r",stdin);
scanf("%d%d%d",&pay,&hap1,&hap2);
scanf("%d",&n);
for(int i=;i<n;i++){
scanf("%d%d",&fr[i].pay,&fr[i].hap);
}
scanf("%d",&m);
for(int i=;i<m;i++){
scanf("%d%d%d",&ho[i].id,&ho[i].pay,&ho[i].hap);
}
int maxhap=-;
int maxho=-;
int maxfr=-;
for(int i=;i<m;i++){
if(ho[i].id==){
if(pay>=ho[i].pay){
if(hap1+ho[i].hap>maxhap){
maxhap=hap1+ho[i].hap;
maxho=i;
maxfr=-;
}
}
}else if(ho[i].id==){
if(pay>=ho[i].pay){
if(hap2+ho[i].hap>maxhap){
maxhap=hap2+ho[i].hap;
maxho=i;
maxfr=-;
}
}
for(int j=;j<n;j++){
if(min(pay,fr[j].pay)*>=ho[i].pay){
if(fr[j].hap+ho[i].hap>maxhap){
maxhap=fr[j].hap+ho[i].hap;
maxho=i;
maxfr=j;
}
}
}
}
}
if(maxho==-){
puts("Forget about apartments. Live in the dormitory.");
}else{
if(maxfr==-){
printf("You should rent the apartment #%d alone.\n",maxho+);
}else{
printf("You should rent the apartment #%d with the friend #%d.\n",maxho+,maxfr+);
}
}
return ;
}

D - Zhenya moves from the dormitory URAL - 2015的更多相关文章

  1. ural 2015 Zhenya moves from the dormitory(模拟)

    2015. Zhenya moves from the dormitory Time limit: 1.0 secondMemory limit: 64 MB After moving from hi ...

  2. Gym 100507D Zhenya moves from the dormitory (模拟)

    Zhenya moves from the dormitory 题目链接: http://acm.hust.edu.cn/vjudge/contest/126546#problem/D Descrip ...

  3. ural 2014 Zhenya moves from parents

    2014. Zhenya moves from parents Time limit: 1.0 secondMemory limit: 64 MB Zhenya moved from his pare ...

  4. Gym 100507C Zhenya moves from parents (线段树)

    Zhenya moves from parents 题目链接: http://acm.hust.edu.cn/vjudge/contest/126546#problem/C Description Z ...

  5. ural2014 Zhenya moves from parents

    Zhenya moves from parents Time limit: 1.0 secondMemory limit: 64 MB Zhenya moved from his parents’ h ...

  6. URAL 2014 Zhenya moves from parents --线段树

    题意:儿子身无分文出去玩,只带了一张他爸的信用卡,当他自己现金不足的时候就会用信用卡支付,然后儿子还会挣钱,挣到的钱都是现金,也就是说他如果有现金就会先花现金,但是有了现金他不会还信用卡的钱.他每花一 ...

  7. zhenya moves from parents

    Zhenya moved from his parents' home to study in other city. He didn't take any cash with him, he onl ...

  8. 【线段树】Gym - 100507C - Zhenya moves from parents

    线段树每个结点维护两个值,分别是这个区间的 负债 和 余钱. 按时间顺序从前往后看的时候,显然负债是单调不减的. 按时间顺序从后往前看的时候,显然余钱也是单调不减的,因为之前如果有余钱,可能会增加现在 ...

  9. NEERC 2014, Eastern subregional contest

    最近做的一场比赛,把自己负责过的题目记一下好了. Problem B URAL 2013 Neither shaken nor stirred 题意:一个有向图,每个结点一个非负值,可以转移到其他结点 ...

随机推荐

  1. AnsiString和String的区别、使用

    16.C/C++语言在CB中的一些特定用法 2)AnsiString是从Delphi中引进来的吗? 答:CB的核心组件VCL是用Object Pascal语言写出的,所以CB的VCL组件的属性有很多都 ...

  2. Linux入门之常用命令(11)复制cp及scp

    [scp] ================== scp 命令 ================== scp 可以在 2个 linux 主机间复制文件: 命令基本格式:        scp [可选参 ...

  3. NOIP2017SummerTraining0706

    个人感受:这套题也依旧在划水,和wqh在一起,然后也没怎么好好想,第一题开始时打了个思维很好的方法,但是事完全错误的:然后就开始第二题,然后第二题枚举20分,然后看答案多了25分,就拿了 45分:第三 ...

  4. 如何创建一个Django项目

    Django 软件框架 软件框架是由其中的各个模块组成,每个模块负责特定的功能,模块与模块之间相互协作来完成软件开发. MVC简介 MVC框架的核心思想是:解耦,让不同的代码块之间降低耦合,增强代码的 ...

  5. 从头编写 asp.net core 2.0 web api 基础框架 (1)

    工具: 1.Visual Studio 2017 V15.3.5+ 2.Postman (Chrome的App) 3.Chrome (最好是) 关于.net core或者.net core 2.0的相 ...

  6. 嵌入式linux开发之工具------tftp

    我在嵌入式linux开发中用到tftp的地方主要有2个方面: 1.是在嵌入式目标板启动时,bootloader启动时通过uEnv文件,下载dtb文件和kernel文件: 2.是在嵌入式目标板启动后,通 ...

  7. Gate One——用web展示Terminal(安装)

    Gate One可以用web来展示Terminal,虽然存在一些小缺陷,基本功能都还可以的,有兴趣的可以折腾一下. 安装环境: 系统:RHEL 6.1 ,系统自带python 2.6.6 下载需要安装 ...

  8. JavaScript 版数据结构与算法(三)链表

    今天,我们要讲的是数据结构与算法中的链表. 链表简介 链表是什么?链表是一种动态的数据结构,这意味着我们可以任意增删元素,它会按需扩容.为何要使用链表?下面列举一些链表的用途: 因为数组的存储有缺陷: ...

  9. php使用curl下载指定大小的文件

    php中使用基于libcurl的curl函数,可以对目标url发起http请求并获取返回的响应内容.通常的请求方式类似如下的代码: public function callFunction($url, ...

  10. mac idea sbt工程打jar包

    1.首先保证sbt已下载,否则下载homebrew:在命令行输入/usr/bin/ruby XXX ->下载完成后在终端输入brew install sbt ->安装完毕后可以打jar包 ...