您的位置:首页 > 其它

BZOJ2947: [Poi2000]促销

2014-12-13 17:07 183 查看

2947: [Poi2000]促销

Time Limit: 10 Sec Memory Limit: 128 MB
Submit: 58 Solved: 33
[Submit][Status]

Description

Bytelandish连锁超市委托你编写一个程序来模拟一项即将施行的促销活动,该活动的规则如下:
●想要参与的顾客,只需把他的个人资料写在帐单上,并把帐单放入投票箱;
●每天活动结束时,数额最大、最小的两张帐单被取出,付款数额最大的顾客将获得一笔奖金,价值为取出的两张帐单的数额之差;
●为了不重复计算,取出的两张帐单不再放回箱子,而剩下的帐单仍保留在箱中,进行第二天的活动。
超市每天的营业额很大,因此可假定:每天活动结束时,箱中至少有两张帐单以供取出。
你的任务是根据每天投入箱中的帐单,计算出这项促销活动期间超市付出的奖金总数额。
任务:
编写一个程序,完成下列工作:
●读入投入箱中的帐单的信息;
●算出促销活动期间的奖金总额;

Input

第一行是一个整数 n(1 <= n <= 5000),表示促销活动历时的天数。

以下的n行,每行包含若干由空格分隔的非负整数。第i+1行的数表示在第i天投入箱子的账单金额。每行的第一行是一个整数k(0 <= k <= 105), 表示当日账单的数目。后面的k个正整数代表这k笔账单的金额,均小于106。
整个活动中涉及到的账单笔数不会超过106 。

Output

唯一一行是一个整数,等于整个促销活动中应该付出的奖金总额。

Sample Input

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

Sample Output

19

题解:
set水过。。。我今天才知道set居然是左闭右开!!!
代码:

#include<cstdio>
#include<cstdlib>
#include<cmath>
#include<cstring>
#include<algorithm>
#include<iostream>
#include<vector>
#include<map>
#include<set>
#include<queue>
#include<string>
#define inf 1000000000
#define maxn 100000
#define maxm 500+100
#define eps 1e-10
#define ll long long
#define pa pair<int,int>
#define for0(i,n) for(int i=0;i<=(n);i++)
#define for1(i,n) for(int i=1;i<=(n);i++)
#define for2(i,x,y) for(int i=(x);i<=(y);i++)
#define for3(i,x,y) for(int i=(x);i>=(y);i--)
#define mod 1000000007
using namespace std;
inline int read()
{
int x=0,f=1;char ch=getchar();
while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
while(ch>='0'&&ch<='9'){x=10*x+ch-'0';ch=getchar();}
return x*f;
}
multiset<int>s;
int main()
{
freopen("input.txt","r",stdin);
freopen("output.txt","w",stdout);
int n=read();ll ans=0;
for1(i,n)
{
int m=read();
for1(j,m)s.insert(read());
multiset<int>::iterator x=s.begin(),y=--s.end();
ans+=(ll)(*y-*x);
s.erase(x);s.erase(y);
}
cout<<ans<<endl;
return 0;
}


View Code
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: