AOJ - Problem 0161 : Sport Meet
4種目の合計タイムの合計タイムが1番小さいチームと2番目に小さいチームと2番目に大きいチームのチーム番号を出力します。
ソートするとよいと思います。
#include <iostream> #include <vector> #include <map> #include <algorithm> using namespace std; typedef pair<int,int> P; int main(){ int n; while( cin >> n , n ){ vector<P> vc; for(int i=0 ; i < n ; i++ ){ int c,m1,m2,m3,m4,s1,s2,s3,s4; cin >> c >> m1 >> s1 >> m2 >> s2 >> m3 >> s3 >> m4 >> s4; int time = m1*60 + s1 + m2*60 + s2 + m3*60 + s3 + m4*60 + s4; P p( time , c ); vc.push_back( p ); } sort( vc.begin() , vc.end() ); cout << vc[0].second << endl; cout << vc[1].second << endl; cout << vc[vc.size()-2].second << endl; } }