1/* 2 ID: neverchanje 3 prog: toj2195 4 LANG: C ++ 11 5 */6 # include <iostream> 7 # include <set> 8 using namespace STD; 9 10 char cmd; 11 int N, Val; 12 INT main () {13 // freopen ("a.txt", "r", stdin); 14 // freopen (". out "," W ", stdout); 15 while (CIN> N) {16 if (! N) break; 17 Multiset <int> S; 18 while (n --) {19 CIN> cmd; 20 if (cmd = 'B ') {21 CIN> val; 22 s. insert (VAL); 23} 24 else {// cmd = 'G' 25 int y = * s. begin (); 26 cout <Y <Endl; 27 s. erase (S. begin (); 28} 29} 30} 31 return 0; 32} 33 34/* 35 Description: 36 Multiset supports repeated elements, in this case, the delete operation may take effect for 37 s. erase (S. begin () is to delete only one minimum element (that is, when there are multiple minimum elements, only one is still deleted) 38 s. erase (* s. begin () deletes the minimum element and 39 identical items */
Uva11136 was not passed because the data in the uva11136 seems to be faulty (other people's AC code is also WA), but the code is okay.
1 /* 2 ID: neverchanje 3 PROG: 4 LANG: C++11 5 */ 6 #include<vector> 7 #include<iostream> 8 #include<cstring> 9 #include<string>10 #include<algorithm>11 #include<cmath>12 #include<cstdio>13 #include<set>14 #include<queue>15 #include<map>16 #define INF 0Xfffffffff17 #define st_size (1<<18)-118 #define maxn19 typedef long long ll;20 using namespace std;21 22 int n,m,x;23 multiset<int> s;24 int main(){25 // freopen("a.txt","r",stdin);26 // freopen(".out","w",stdout);27 while(cin>>n)28 {29 if(!n) break;30 s.clear();31 int sum=0;32 33 for(int j=0;j<n;j++){34 cin>>m;35 for(int i=0;i<m;i++){ 36 cin>>x;37 s.insert(x);38 }39 sum+=*--s.end()-*s.begin();40 s.erase(--s.end());41 s.erase(s.begin());42 }43 cout<<sum<<endl;44 }45 return 0;46 }47 48 /*49 DESCRIPTION:50 51 */
View code