Lunch Time

Time Limit: 2 Seconds Memory Limit: 65536 KB

The 999th Zhejiang Provincial Collegiate Programming Contest will be held in Marjar University. The canteen of Marjar University is making preparations for this grand competition. The canteen provides a lunch set of three types: appetizer, main course and dessert. Each type has several dishes with different prices for choosing.

Edward is the headmaster of Marjar University. One day, to inspect the quality of dishes, he go to the canteen and decides to choose a median set for his lunch. That means he must choose one dish from each of appetizers, main courses and desserts. Each chosen dish should at the median price among all dishes of the same type.

For example, if there are five dessert dishes selling at the price of 2, 3, 5, 10, 30, Edward should choose the dish with price 5 as his dessert since its price is located at the median place of the dessert type. If the number of dishes of a type is even, Edward will choose the dish which is more expensive among the two medians.

You are given the list of all dishes, please write a program to help Edward decide which dishes he should choose.

Input

There are multiple test cases. The first line of input contains an integer T indicating the number of test cases. For each test case:

The first line contains three integers S, M and D (1 <= S, M, D <= 100), which means that there are S dishes of appetizer, M dishes of main course and D dishes of dessert.

Then followed by three parts. The first part contains S lines, the second and the last part contains M and D lines respectively. In each line of the three parts, there is a string and an integer indicating the name and the price of a dish. The name of dishes will only consist of non-whitespace characters with no more than 50 characters. The price of dishes are non-negative integers less than or equal to 1000. All dish names will be distinct.

Output

For each test case, output the total price of the median set, together with the names of appetizer, main course and dessert, separated by a single space.

Sample Input

2

1 3 2

Fresh_Cucumber 4

Chow_Mein 5

Rice_Served_with_Duck_Leg 12

Fried_Vermicelli 7

Steamed_Dumpling 3

Steamed_Stuffed_Bun 4

2 3 1

Stir-fried_Loofah_with_Dried_Bamboo_Shoot 33

West_Lake_Water_Shield_Soup 36

DongPo’s_Braised_Pork 54

West_Lake_Fish_in_Vinegar 48

Longjing_Shrimp 188

DongPo’s_Crisp 18

Sample Output

15 Fresh_Cucumber Fried_Vermicelli Steamed_Stuffed_Bun

108 West_Lake_Water_Shield_Soup DongPo’s_Braised_Pork DongPo’s_Crisp

#include <iostream>
#include <string>
#include <stdio.h>
#include<algorithm> using namespace std; struct node
{
string s;
int result;
}ap[110],ma[110],de[110]; bool cmp(node a,node b)
{
return a.result<b.result;
}
int main()
{
int T,S,M,D,i,s,m,d; int sum; scanf("%d",&T); while(T--)
{
scanf("%d %d %d",&S,&M,&D); sum=0; for(i=0;i<S;i++)
{
cin>>ap[i].s>>ap[i].result;
} for(i=0;i<M;i++)
{
cin>>ma[i].s>>ma[i].result;
} for(i=0;i<D;i++)
{
cin>>de[i].s>>de[i].result;
} sort(ap,ap+S,cmp);
sort(ma,ma+M,cmp);
sort(de,de+D,cmp); if(S%2==0)
{
int ss=S/2;
if(ap[ss].result>ap[ss-1].result)
{
sum+=ap[ss].result;
s=ss;
}
else
{
sum+=ap[ss-1].result;
s=ss-1;
} }
else
{
sum+=ap[S/2].result;
s=S/2;
} if(M%2==0)
{
int ss=M/2;
if(ma[ss].result>ma[ss-1].result)
{
sum+=ma[ss].result;
m=ss;
}
else
{
sum+=ma[ss-1].result;
m=ss-1;
} }
else
{
sum+=ma[M/2].result;
m=M/2;
} if(D%2==0)
{
int ss=D/2;
if(de[ss].result>de[ss-1].result)
{
sum+=de[ss].result;
d=ss;
}
else
{
sum+=de[ss-1].result;
d=ss-1;
} }
else
{
sum+=de[D/2].result;
d=D/2;
}
cout<<sum<<" "<<ap[s].s<<" "<<ma[m].s<<" "<<de[d].s<<endl;
} return 0; }

版权声明:本文为博主原创文章,未经博主允许不得转载。

第十二届浙江省大学生程序设计大赛-Lunch Time 分类: 比赛 2015-06-26 14:30 5人阅读 评论(0) 收藏的更多相关文章

  1. 第十二届浙江省大学生程序设计大赛-Team Formation 分类: 比赛 2015-06-26 14:22 50人阅读 评论(0) 收藏

    Team Formation Time Limit: 3 Seconds Memory Limit: 131072 KB For an upcoming programming contest, Ed ...

  2. 第十二届浙江省大学生程序设计大赛-Demacia of the Ancients 分类: 比赛 2015-06-26 14:39 30人阅读 评论(0) 收藏

    Demacia of the Ancients Time Limit: 2 Seconds Memory Limit: 65536 KB There is a popular multiplayer ...

  3. 第十二届浙江省大学生程序设计大赛-Capture the Flag 分类: 比赛 2015-06-26 14:35 10人阅读 评论(0) 收藏

    Capture the Flag Time Limit: 2 Seconds Memory Limit: 65536 KB Special Judge In computer security, Ca ...

  4. 第十二届浙江省大学生程序设计大赛-May Day Holiday 分类: 比赛 2015-06-26 14:33 10人阅读 评论(0) 收藏

    May Day Holiday Time Limit: 2 Seconds Memory Limit: 65536 KB As a university advocating self-learnin ...

  5. 第十二届浙江省大学生程序设计大赛-Beauty of Array 分类: 比赛 2015-06-26 14:27 12人阅读 评论(0) 收藏

    Beauty of Array Time Limit: 2 Seconds Memory Limit: 65536 KB Edward has an array A with N integers. ...

  6. 第十二届浙江省大学生程序设计大赛-Ace of Aces 分类: 比赛 2015-06-26 14:25 12人阅读 评论(0) 收藏

    Ace of Aces Time Limit: 2 Seconds Memory Limit: 65536 KB There is a mysterious organization called T ...

  7. 团体程序设计天梯赛L1-020 帅到没朋友 2017-03-22 17:46 72人阅读 评论(0) 收藏

    L1-020. 帅到没朋友 时间限制 200 ms 内存限制 65536 kB 代码长度限制 8000 B 判题程序 Standard 作者 陈越 当芸芸众生忙着在朋友圈中发照片的时候,总有一些人因为 ...

  8. 团体程序设计天梯赛L1-017 到底有多二 2017-03-22 17:31 155人阅读 评论(0) 收藏

    L1-017. 到底有多二 时间限制 400 ms 内存限制 65536 kB 代码长度限制 8000 B 判题程序 Standard 作者 陈越 一个整数"犯二的程度"定义为该数 ...

  9. 2012年"浪潮杯"山东省第三届ACM大学生程序设计竞赛--n a^o7 ! 分类: 比赛 2015-06-09 17:16 14人阅读 评论(0) 收藏

    n a^o7 ! Time Limit: 1000ms   Memory limit: 65536K  有疑问?点这里^_^ 题目描述 All brave and intelligent fighte ...

随机推荐

  1. winner tree 胜者树

    在树形选择排序中,利用锦标赛思想建立的树称为胜者树. 1.每个非终端节点存储的是左右孩子节点中的优胜者. 2.通过减少比较次数,提高效率. 3.胜者树就是一颗特殊的线段树. 一.构建树 Procedu ...

  2. zabbix监控企业esxi虚拟机

    zabbix监控企业esxi虚拟机 作者:尹正杰 版权声明:原创作品,谢绝转载!否则将追究法律责任. 我来公司有一段时间了,最近也发现模型部有测试和开发反应某台机器登陆不上去了,结果登陆esxi服务器 ...

  3. Appium-android环境的快速搭建

    1.Android的要求: Android的sdk api>=16 appium支持android在linux,osx(mac),window平台 2.Appium的安装与启动: 安装: (1) ...

  4. bzoj1758 [Wc2010]重建计划 & bzoj2599 [IOI2011]Race

    两题都是树分治. 1758这题可以二分答案avgvalue,因为avgvalue=Σv(e)/s,因此二分后只需要判断Σv(e)-s*avgvalue是否大于等于0,若大于等于0则调整二分下界,否则调 ...

  5. 南阳oj27题

    水池数目 时间限制:3000 ms  |  内存限制:65535 KB 难度:4 描述 南阳理工学院校园里有一些小河和一些湖泊,现在,我们把它们通一看成水池,假设有一张我们学校的某处的地图,这个地图上 ...

  6. ORACLE 默认密码确认

    select USER_NAME USER_WITH_DEFAULT_PASSWORD from ( select fnd_web_sec.validate_login('AME_INVALID_AP ...

  7. JSTL标签,EL表达式,OGNL表达式,struts2标签 汇总

    一下纯属个人总结摘抄,总结一起方便查看,解决疑问,有遗漏或错误,还请指出.       1,JSTL标签总结: a).JSTL标签有什么用?          JSTL是由JCP(Java Commu ...

  8. Oracle中的MD5加密

    一.技术点 1. DBMS_OBFUSCATION_TOOLKIT.MD5 DBMS_OBFUSCATION_TOOLKIT.MD5是MD5编码的数据包函数,但偶在使用select DBMS_OBFU ...

  9. 如何在真机上调试Android应用程序(图文详解)(zz)

    http://www.cnblogs.com/lanxuezaipiao/archive/2013/03/11/2953564.html   1.首先将手机设置为调试模式 方法:设置——应用程序——开 ...

  10. CSS(Cascading Style Sheet,叠层样式表),作用是美化HTML网页。

    CSS(Cascading Style Sheet,叠层样式表),作用是美化HTML网页. /*注释区域*/    此为注释语法 一.样式表 (一)样式表的分类 1.内联样式表 和HTML联合显示,控 ...