标签:
Each Mal-Wart supermarket has prepared a promotion scheme run by the following rules:
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.
5 3 1 2 3 2 1 1 4 10 5 5 1 0 1 2 2 2 1 2 2 1 2 0
19 2
动态数组最大值最小值差值的和。Multiset。
1 #include<cstdio> 2 #include<set> 3 using namespace std; 4 typedef long long LL; 5 int main() 6 { 7 LL n,x,maxn,mind,d,sum; 8 multiset<LL> s; 9 while(scanf("%I64d",&n)&&n!=0) 10 { 11 sum=0; 12 s.clear(); 13 for(LL i=0; i<n; i++) 14 { 15 scanf("%I64d",&x); 16 for(LL j=0; j<x; j++) 17 { 18 scanf("%I64d",&d); 19 s.insert(d); 20 } 21 multiset<LL>::iterator it; 22 it=s.begin(); 23 mind=*it; 24 s.erase(it); 25 it=s.end(),it--; 26 maxn=*it; 27 s.erase(it); 28 sum+=maxn-mind; 29 } 30 printf("%lld\n",sum); 31 } 32 return 0; 33 }
标签:
原文地址:http://www.cnblogs.com/wpnan/p/4323142.html