Each Mal-Wart supermarket has prepared a promotion scheme run by the following rules:

  • A client who wants to participate in the promotion (aka a sucker) must write down their phone number on the bill of their purchase and put the bill into a special urn.
  • Two bills are selected from the urn at the end of each day: first the highest bill is selected and then the lowest bill is selected. The client who paid the largest bill receives a monetary prize equal to the difference between his bill and the lowest bill of the day.
  • Both selected bills are not returned to the urn while all the remaining ones are kept in the urn for the next day.
  • Mal-Wart has many clients such that at the end of each day there are at least two bills in the urn.
  • It is quite obvious why Mal-Wart is doing this: they sell crappy products which break quickly and irreparably. They give a short-term warranty on their products but in order to obtain a warranty replacement you need the bill of sale. So if you are gullible enough to participate in the promotion you will regret it.

Your task is to write a program which takes information about the bills put into the urn and computes Mal-Wart's cost of the promotion.

The input contains a number of cases. The first line in each case contains an integer n, 1<=n<=5000, the number of days of the promotion. Each of the subsequent n lines contains a sequence of non-negative integers separated by whitespace. The numbers in the (i+1)-st line of a case give the data for the i-th day. The first number in each of these lines, k, 0≤k≤105, is the number of bills and the subsequent k numbers are positive integers of the bill amounts. No bill is bigger than 106. The total number of all bills is no bigger than 106. The case when n = 0 terminates the input and should not be processed.

For each case of input print one number: the total amount paid to the clients by Mal-Wart as the result of the promotion.

Sample input

5
3 1 2 3
2 1 1
4 10 5 5 1
0
1 2
2
2 1 2
2 1 2
0

Output for sample input

19
2 动态数组最大值最小值差值的和。Multiset。
 #include<cstdio>
#include<set>
using namespace std;
typedef long long LL;
int main()
{
LL n,x,maxn,mind,d,sum;
multiset<LL> s;
while(scanf("%I64d",&n)&&n!=)
{
sum=;
s.clear();
for(LL i=; i<n; i++)
{
scanf("%I64d",&x);
for(LL j=; j<x; j++)
{
scanf("%I64d",&d);
s.insert(d);
}
multiset<LL>::iterator it;
it=s.begin();
mind=*it;
s.erase(it);
it=s.end(),it--;
maxn=*it;
s.erase(it);
sum+=maxn-mind;
}
printf("%lld\n",sum);
}
return ;
}

11136-Hoax or what的更多相关文章

  1. UVA 11136 - Hoax or what (可以提交了,不会Submission error了)

    看题传送门:http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem ...

  2. set UVA 11136 Hoax or what

    题目传送门 题意:训练指南P245 分析:set维护,查询删除最大最小值 #include <bits/stdc++.h> using namespace std; typedef lon ...

  3. uva 11136 - Hoax or what

    用两个优先队列来实现,因为队列只能从一头出去: 所以维护一个数组,来标记这个队列的已经出列而另外一个队列没有出列的元素: 到时候再把他们删了就行: #include<cstdio> #in ...

  4. UVA 11136 Hoax or what (multiset)

    题目大意: 超时进行促销.把账单放入一个箱子里 每次拿取数额最大的和最小的,给出 最大-最小  的钱. 问n天总共要给出多少钱. 思路分析: multiset 上直接进行模拟 注意要使用long lo ...

  5. UVa 11136 Hoax or what (STL)

    题意:有 n 天,每天有m个数,开始的前一天没有数据,然后每天从这个里面拿出一个最大的和最小的,求 n 天的最大的和最小的差值相加. 析:一看就知道用set啊,多简单的STL,不过要注意,开long ...

  6. Hoax or what UVA - 11136(multiset的应用)

    刚开始把题意理解错了,结果样例没过,后来发现每天只处理最大和最小的,其余的不管,也就是说昨天的元素会影响今天的最大值和最小值,如果模拟的话明显会超时,故用multiset,另外发现rbegin()的功 ...

  7. Hoax or what

    Hoax or what 题意是询问一个动态序列的最小值和最大值. 可以用multiset来实现. #include <stdio.h> #include <set> usin ...

  8. 优化Hoax or what的思考

    在抽取MinHeap的时候,涉及到重载,覆盖,虚函数等,有几点之前没注意到的问题在这里总结下: 1. 覆盖(override)只要是函数同名就会被覆盖,子类指针若调用父类的同名不同参数的函数的话,会在 ...

  9. SQL Server 2008 R2——VC++ ADO 操作 存储过程 向datetime类型参数传入空值

    ==================================声明================================== 本文原创,转载在正文中显要的注明作者和出处,并保证文章的完 ...

  10. 使用变量替换批量部署GoldenGate

    GoldenGate运行时允许在参数文件中动态指定一个值,即在参数文件中使用一个变量,而不是一个静态的值,当启动OGG进程时,根据环境动态加载此变量的值,达到在不同环境中,通过变量定义,实现多个环境的 ...

随机推荐

  1. android应用程序的组成部分

    android 应用程序的组成部分 activity 应用表示层,应用程序中每一个UI都是通过activity类或者多个扩展实现的.activity使用fragment和视图来布局和显示信息,以及响应 ...

  2. Spring简单的文件配置

    Spring简单的文件配置 “计应134(实验班) 凌豪” 一.Spring文件配置 spring至关重要的一环就是装配,即配置文件的编写,接下来我按刚才实际过程中一步步简单讲解. 首先,要在web. ...

  3. GO语言搭建

    最近对GO语言产生了浓厚的兴趣.因为GO语言不仅仅可以开发桌面.web程序,最吸引我的是安卓大有往GO语言全方位靠拢的趋势,自家的系统还是用自家的语言开发比较靠谱. 用一句话来说:Go语言是谷歌200 ...

  4. C#控件、窗体置顶

    //控件置于顶层和底层 panel.BringToFront();//置于顶层 panel.SendToBack();//置于底层 //窗体置顶 TopMost = true;

  5. wget www.baidu.com执行流程分析

    下载网页的关键函数: main.c(main) b 1394 url_parse:解析url,获取url相关信息,返回结构体 struct url 的指针,存于 url_parsed retrieve ...

  6. Java String 和 StringBuffer的区别

    1.String类的定义是这样的: public final class String extends Object implements   Serializable, Comparable< ...

  7. SQL Server用户自定义类型与统计信息

    用户自定义数据类型不支持统计信息! 所以查询对它的查询会慢一些.

  8. N沟道增强型MOS管双向低频开关电路

    MOS-N 场效应管 双向电平转换电路 -- 适用于低频信号电平转换的简单应用 如上图所示,是 MOS-N 场效应管 双向电平转换电路.双向传输原理: 为了方便讲述,定义 3.3V 为 A 端,5.0 ...

  9. MySQL数据处理函数

    数据处理函数 有时从数据库表中获取到的数据须要进行一些处理. 如将小写字母替换为对应的大写字母.这个处理过程能够在客户机上进行.也能够在数据库上进行. 数据库上进行会更高效.数据库中有对应的数据处理函 ...

  10. JS学习笔记(三)函数

    js中的方法名一般都是首字母小写,其余单词首字母大写的规范. 声明 function 函数名(参数列表) { // 函数体 return 返回值; } 调用 函数名(); (js中花括号喜欢用这种方式 ...