促销活动 (Hoax or what,UVa 11136)
1 #include <iostream> 2 #include <string.h> 3 #include <string> 4 #include <fstream> 5 #include <algorithm> 6 #include <stdio.h> 7 #include <vector> 8 #include <queue> 9 #include <set> 10 #include <cmath> 11 using namespace std; 12 const double eps = 1e-8; 13 const double pi=acos(-1.0); 14 const int INF=0x7fffffff; 15 unsigned long long uINF = ~0LL; 16 #define MAXN 1007 17 #define mod 1000000007 18 typedef long long LL; 19 multiset<int> s; 20 int main() 21 { 22 int n,k; 23 while(scanf("%d",&n),n!=0) 24 { 25 s.clear(); 26 int ans=0,temp; 27 for(int i=0;i<n;i++) 28 { 29 scanf("%d",&k); 30 for(int j=0;j<k;j++) 31 { 32 scanf("%d",&temp); 33 s.insert(temp); 34 } 35 int minn,maxx; 36 if(s.size()>0) 37 { 38 multiset<int>::iterator it; 39 it=s.begin();minn=*it; 40 it=s.end();it--;maxx=*it; 41 s.erase(it); 42 if(s.size()>0) 43 { 44 it=s.begin(); 45 s.erase(it); 46 } 47 ans+=maxx-minn; 48 } 49 } 50 printf("%d\n",ans); 51 } 52 53 return 0; 54 }
提交不了 暂存 下次提交