2947: [Poi2000] Promotion time limit:10 Sec Memory limit:128 MB
submit:58 solved:33
[Submit] [Status] Description
Bytelandish Chain supermarket commissioned you to write a program to simulate a forthcoming promotion, the rules of the activity are as follows:
To participate in the customer, just write his personal information on the bill, and put the bill into the ballot box;
At the end of each day, the largest and smallest two bills are taken out, and the customer with the largest payment will receive a bonus, which is worth the difference in the amount of the two bills taken out;
In order not to repeat the calculation, the two bills taken out are no longer returned to the box, while the remaining bills remain in the box for the next day's activity.
The daily turnover of supermarkets is large, so it can be assumed that at the end of each day, there are at least two bills in the box for removal.
Your task is to calculate the total amount of bonuses paid by supermarkets during the campaign, based on the daily Bill in the box.
Task:
Write a program to complete the following tasks:
Read the information of the bill into the input box;
Calculate the total amount of bonuses during the promotion period;
Input The first line is an integer n (1 <= n <= 5000) that represents the number of days the campaign lasted. The following n rows, each containing a number of non-negative integers separated by spaces. The number of line i+1 indicates the amount of the bill to be put into the box on day I. The first line of each row is an integer k (0 <= K <= 105) that represents the number of daily bills. The following k positive integers represent the amount of the K-bill, which is less than 106. There will be no more than 106 bill pens involved in the entire event. OutputThe only line is an integer equal to the total amount of the bonus that should be paid for the entire promotion. Sample Input5
3 1 2 3
2 1 1
4 10 5) 5 1
0
1 2
Sample Output
19
The following:set water over ... I just realized today that set is left closed right!!! Code:
1#include <cstdio>2#include <cstdlib>3#include <cmath>4#include <cstring>5#include <algorithm>6#include <iostream>7#include <vector>8#include <map>9#include <Set>Ten#include <queue> One#include <string> A #defineINF 1000000000 - #defineMAXN 100000 - #defineMAXM 500+100 the #defineEPS 1e-10 - #definell Long Long - #definePA pair<int,int> - #defineFor0 (i,n) for (int i=0;i<= (n); i++) + #defineFor1 (i,n) for (int i=1;i<= (n); i++) - #defineFor2 (i,x,y) for (int i= (x); i<= (y); i++) + #defineFor3 (i,x,y) for (int i= (x); i>= (y); i--) A #defineMoD 1000000007 at using namespacestd; -InlineintRead () - { - intx=0, f=1;CharCh=GetChar (); - while(ch<'0'|| Ch>'9'){if(ch=='-') f=-1; ch=GetChar ();} - while(ch>='0'&&ch<='9') {x=Ten*x+ch-'0'; ch=GetChar ();} in returnx*F; - } tomultiset<int>s; + intMain () - { theFreopen ("Input.txt","R", stdin); *Freopen ("output.txt","W", stdout); $ intN=read (); ll ans=0;Panax Notoginseng For1 (i,n) - { the intm=read (); + For1 (j,m) S.insert (read ()); Amultiset<int>::iterator X=s.begin (), y=--s.end (); theans+= (LL) (*y-*x); + s.erase (x); s.erase (y); - } $cout<<ans<<Endl; $ return 0; -}
View Code
BZOJ2947: [Poi2000] Promotions