Topic links
Test instructions: N days, each day into a box to put the number of M, put the maximum Max and the smallest min to do the difference, and the two numbers removed, for n days after the and
The principle of multiset and set is similar, multiset can save multiple identical numbers, and set is unique, and is arranged from small to large
Summary of Set Container
Set also has Lower_bound (x) {Returns the first position greater than or equal to X} and Upper_bound (x) {Returns the position of the first greater than x}
#include <iostream>#include<Set>#include<algorithm>#include<cstring>#include<cstdio>using namespaceStd;multiset<int>s;intMain () {intn,m; while(SCANF ("%d", &n)! = EOF &&N) {s.clear (); Long LongAns =0; intMINN,MAXN; for(inti =1; I <= N; i++) {scanf ("%d", &m); for(intj =1; J <= M; J + +) { intthing; scanf ("%d", &thing); S.insert (thing); } if(S.size () >0) {Multiset<int>:: Iterator it; It=S.end (); It--; MAXN= *it; S.erase (IT); //originally written here S.erase (MAXN), error, should be removed all MAXN, here just delete ait =S.begin (); Minn= *it;//If there is only one number left, both the largest and the smallest if(S.size () >0) {It=S.begin (); S.erase (IT); } ans+ = MAXN-Minn; }} printf ("%lld\n", ans); } return 0;}
Uva11136hoax or what (Application of Multiset)