Problem:
体育祭Sport Meet
秋の体育祭が行われます。種目は徒競走、ボール運び、障害物競走、リレーの4種目です。参加チームは
n
チームで、この4種目の合計タイムが最も小さいチームが「優勝」、次に小さいチームが「準優勝」、そして、最下位より2番目のチームを「ブービー賞」として表彰したいと思います。
各チームの成績を入力として、「優勝」、「準優勝」、「ブービー賞」のチームを出力するプログラムを作成してください。
ただし、チームにはそれぞれ 1 から
n
のチーム番号が割り当てられています。
Input
複数のデータセットの並びが入力として与えられます。入力の終わりはゼロひとつの行で示されます。
各データセットは以下の形式で与えられます。
n
record
1
record
2
:
record
n
１行目に対象となるチームの数
n
(4 ≤
n
≤ 100000)、続く
n
行に
i
番目のチームの情報が与えられます。各チームの情報は以下の形式で与えられます。
id
m1
s1
m2
s2
m3
s3
m4
s4
id
(1 ≤
id
≤
n
)はチーム番号、
m1
,
s1
はそれぞれ徒競走のタイムの分と秒、
m2
,
s2
はそれぞれボール運びのタイムの分と秒、
m3
,
s3
はそれぞれ障害物競走のタイムの分と秒、
m4
,
s4
はそれぞれリレーのタイムの分と秒を表します。分と秒はともに0 以上 59 以下の整数です。また、合計タイムが複数のチームで同じになるような入力はないものとします。
Output
入力データセットごとに以下の形式でチーム番号を出力します。
1 行目 優勝のチーム番号
2 行目 準優勝のチーム番号
3 行目 ブービー賞のチーム番号
Sample Input
8
34001 3 20 3 8 6 27 2 25
20941 3 5 2 41 7 19 2 42
90585 4 8 3 12 6 46 2 34
92201 3 28 2 47 6 37 2 58
10001 3 50 2 42 7 12 2 54
63812 4 11 3 11 6 53 2 22
54092 3 33 2 54 6 18 2 19
25012 3 44 2 58 6 45 2 46
4
1 3 23 1 23 1 34 4 44
2 5 12 2 12 3 41 2 29
3 5 24 1 24 2 0 3 35
4 4 49 2 22 4 41 4 23
0
Output for the Sample Input
54092
34001
10001
1
3
2

Submitted solutions:

code_snippet: #include <iostream>
using namespace std;
int main()
{
    int m,s,n,id[100005],timeteam[100005],ranking[100005],temp;
    
    while(true)
    {
        cin >> n;
        if(n==0){break;}
        for(int i = 1;i <= n;i++)
        {
            cin >> id[i];
            timeteam[i]=0;
            for(int j = 1;j <= 4;j++)
            {
                cin >> m >> s;
                timeteam[i]+=m*60;
                timeteam[i]+=s;
            }
        }
        temp=1;
        for(int j = 1;j <= 100000;j++)
        {
            for(int i = 1;i <= n;i++)
            {
                if(timeteam[i]==j)
                {
                    if(temp==1||temp==2||temp==(n-1)){cout << id[i] << endl;}
                    temp++;
                }
            }
        }
    }
    return 0;
}
accuracy: 1
time_ms: 350
memory_kb: 3140
final_rank: 20

code_snippet: #include<bits/stdc++.h>
using namespace std;
typedef pair<int, int> PI;
int main(){
    int n, m1, s1, m2, s2, m3, s3, m4, s4;
    PI id[100010];
    while(cin >> n, n!=0){
        for(int i=0;i<n;i++){
            cin >> id[i].second >> m1 >> s1 >> m2 >> s2 >> m3 >> s3 >> m4 >> s4;
            id[i].first = m1*60+s1 + m2*60+s2 + m3*60+s3 + m4*60+s4;
        }
        sort(id, id+n);
        cout << id[0].second << endl << id[1].second << endl << id[n-2].second << endl;
    }
    return(0);
}
accuracy: 1
time_ms: 10
memory_kb: 3780
final_rank: 19

code_snippet: #include <bits/stdc++.h>
using namespace std;

int n, id, m, s, u;

int main() {
	cin >> n;

	while (n) {
		vector<pair<int, int> > p(n);

		for (int i = 0; i < n; i++) {
			u = 0;
			cin >> id;

			for (int j = 0; j < 4; j++) {
				cin >> m >> s;

				u += m * 100;

				if (u % 100 + s >= 60) {
					u += s + 40;
				}
				else
					u += s;
			}

			p[i] = { u, id };
		}

		sort(p.begin(), p.end());

		cout << p[0].second << endl << p[1].second << endl
			<< p[n - 2].second << endl;

		cin >> n;
	}
}
accuracy: 1
time_ms: 10
memory_kb: 3116
final_rank: 5

code_snippet: #include<iostream>
#include<algorithm>
#include<map>
#include<queue>
#include<stack>
#include<set>
#include<bitset>
#include<vector>
#include<string>
#include <iomanip>
#include <deque>
#include<list>
#include<cmath>
#define rep(i,n) for(int i=0;i<(n);i++)
using namespace std;
using ll=long long;
using P=pair<int,int>;
using P_S=pair<int,string>;
using P_D=pair<double,int>;
using T=tuple<int,int,char,ll,string>;

int main(){
    while(1){
        int n;
        cin>>n;
        if(n==0) break;
        vector<P> time(n);
        rep(i,n){
        int id,m1,s1,m2,s2,m3,s3,m4,s4;
        cin>>id>>m1>>s1>>m2>>s2>>m3>>s3>>m4>>s4;
        int ans=m1*60+s1+m2*60+s2+m3*60+s3+m4*60+s4;
        time[i].first=ans;
        time[i].second=id;
        }
        sort(time.begin(),time.end());
        cout<<time[0].second<<endl;
        cout<<time[1].second<<endl;
        cout<<time[n-2].second<<endl;
        }
}
accuracy: 1
time_ms: 10
memory_kb: 3052
final_rank: 3

code_snippet: #include <iostream>
#include <vector>
#include <algorithm>
using namespace std;

int main(){
    while(1){
        int n;
        cin >> n;
        if(n == 0) break;

        vector<vector<int>> a(n);
        for(int i=0; i<n; i++){
            int id;
            cin >> id;
            int time = 0;
            for(int j=0; j<4; j++){
                int m,s;
                cin >> m >> s;
                time += 60*m +s;
            }
            a[i] = {time, id};
        }
        sort(a.begin(), a.end());
        cout << a[0][1] << endl;
        cout << a[1][1] << endl;
        cout << a[n-2][1] << endl;
    }
    return 0;
}
accuracy: 1
time_ms: 10
memory_kb: 3412
final_rank: 16

code_snippet: #include <iostream>
#include <algorithm>

struct Team {
	int id;
	int time;
};
bool operator < (const Team& t1, const Team& t2) { return t1.time < t2.time; }

int main()
{
	int n;
	while (true) {
		std::cin >> n;
		if (n==0) break;
		Team* teams = new Team[n];
		for (int i=0; i<n; i++) {
			int id, m1, s1, m2, s2, m3, s3, m4, s4;
			std::cin >> id >> m1 >> s1 >> m2 >> s2 >> m3 >> s3 >> m4 >> s4;
			teams[i].id = id;
			teams[i].time = 60*(m1+m2+m3+m4) + s1+s2+s3+s4; 
		}
		std::sort(teams, teams + n);
		std::cout << teams[0].id << std::endl;
		std::cout << teams[1].id << std::endl;
		std::cout << teams[n-2].id << std::endl;
		delete[] teams;
	}
	return 0;
}
accuracy: 1
time_ms: 10
memory_kb: 3192
final_rank: 10

code_snippet: #include <iostream>
#include <vector>
#include <map>
#include <algorithm>
using namespace std;

int main(void){
  int n;
  int id,m1,s1,m2,s2,m3,s3,m4,s4;
  int t;
  while(1){
    cin>>n;
    if(n==0)break;
    map<int,int> d;
    vector<int> v;
    for(int i=0;i<n;i++){
      cin>>id>>m1>>s1>>m2>>s2>>m3>>s3>>m4>>s4;
      t=60*(m1+m2+m3+m4)+s1+s2+s3+s4;
      v.push_back(t);
      d[t]=id;
    }
    sort(v.begin(),v.end());
    cout<<d[v[0]]<<endl;
    cout<<d[v[1]]<<endl;
    cout<<d[v[v.size()-2]]<<endl;
  }
  return 0;
}
accuracy: 1
time_ms: 10
memory_kb: 3344
final_rank: 13

code_snippet: #include <bits/stdc++.h>
using namespace std;
int main(void){
    int n;
    while (cin>>n) {
        if (n==0) {
            break;
        } else {
            int id,m,s;
            std::map<int, int> map;
            for (int i=0;i<n;i++) {
                cin>>id;
                int sum=0;
                for (int j=0;j<4;j++) {
                    cin>>m>>s;
                    sum+=60*m+s;
                }
                map.insert(make_pair(sum,id));
            }
            auto itr=map.begin();
            for (int k=0;k<n;k++) {
                if (k==0||k==1||k==n-2) {
                    cout<<(itr->second)<<endl;
                    itr=next(itr,1);
                } else {
                    itr=next(itr,1);
                }
            }
        }
    }
}
accuracy: 1
time_ms: 10
memory_kb: 3336
final_rank: 12

code_snippet: #include <bits/stdc++.h>

using namespace std;

class Team {
public:
	int id;
	int time;
};

Team TeamData[10000];

bool cmp(const Team& t1, const Team& t2) {
	return t1.time < t2.time;
}

int main(void) {
	int n, m, s, sum;

	while (cin >> n, n) {
		for (int i = 0; i < n; i++) {
			cin >> TeamData[i].id;
			sum = 0;
			for (int j = 0; j < 4; j++) {
				cin >> m >> s;
				sum += m * 60 + s;
			}
			TeamData[i].time = sum;
		}

		sort(TeamData, TeamData + n,cmp);
		cout << TeamData[0].id << endl << TeamData[1].id << endl << TeamData[n - 2].id << endl;
	}

	return 0;
}
accuracy: 1
time_ms: 10
memory_kb: 3164
final_rank: 6

code_snippet: #include <iostream>
#include <vector>
#include <utility>
#include <algorithm>
using namespace std;

int solve_testcase() {
    int N; cin >> N;
    if(N == 0) return 1;

    vector< pair<int, int> > info;
    for(int i=0; i<N; i++) {
        int id; cin >> id;
        int sum = 0;
        for(int k=0; k<4; k++) {
            int m, s; cin >> m >> s;
            int total_time = m * 60 + s;
            sum += total_time;
        }
        info.emplace_back(sum, id);
    }

    sort(info.begin(), info.end());
    cout << info[0].second << endl;
    cout << info[1].second << endl;
    cout << info[N-2].second << endl;
    return 0;
}

int main() {
    while(!solve_testcase());
    return 0;
}
accuracy: 1
time_ms: 10
memory_kb: 3092
final_rank: 4

code_snippet: #include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define pp pair<int,int>
#define ll long long
int inf=100000000;
ll INF=100000000000000000;
ll are=1000000007;

int main() {
    while  (true){
        int n;
        cin >> n;
        if (n==0) break;
        vector<pp> a(n);
        rep(i,n){
            a.at(i).first=0;
            int u=0,y=0;
            cin >> a.at(i).second;
            rep(j,4){
                cin >> u >> y;
                a.at(i).first+=u*60+y;
            }
        }
        sort(a.begin(),a.end());
        cout << a.at(0).second << endl << a.at(1).second << endl <<  a.at(n-2).second << endl;
    }
}
accuracy: 1
time_ms: 10
memory_kb: 3016
final_rank: 1

code_snippet: #include <bits/stdc++.h>
using namespace std;

using pii = pair<int, int>;

int main() {
    int n;
    while(cin >> n, n) {
        vector<pii> scores;
        for(int i = 0; i < n; ++i) {
            int id; cin >> id;
            int t = 0;
            for(int j = 0; j < 4; ++j) {
                int m, s; cin >> m >> s;
                t += m * 60 + s;
            }
            scores.emplace_back(t, id);
        }
        sort(begin(scores), end(scores));

        cout << scores[0].second << endl;
        cout << scores[1].second << endl;
        cout << scores[n - 2].second << endl;
    }
}
accuracy: 1
time_ms: 10
memory_kb: 3184
final_rank: 8

code_snippet: #include <iostream>
#include <vector>
#include <map>

#define int long long

using namespace std;


class Solver {

};

signed main() {
	while (true) {
		int n;
		cin >> n;
		if (n == 0)break;

		map<int, int> vals;
		for (int i = 0; i < n; i++) {
			int id, m1, s1, m2, s2, m3, s3, m4, s4;
			cin >> id >> m1 >> s1 >> m2 >> s2 >> m3 >> s3 >> m4 >> s4;
			int val = m1 * 60 + s1 + m2 * 60 + s2 + m3 * 60 + s3 + m4 * 60 + s4;
			vals.emplace(val,id);
		}

		int itr = 0;
		for (auto val : vals) {
			if (itr == 0 || itr == 1 || itr == vals.size() - 2) {
				cout << val.second << endl;
			}
			itr++;
		}
	}

}
accuracy: 1
time_ms: 10
memory_kb: 3388
final_rank: 14

code_snippet: #include <bits/stdc++.h>
using namespace std;
const double eps=1e-9;
typedef vector<int> vi;
typedef long long ll;
int A[5],B[5];
string rule[5][5];
#define pb push_back
string s;
int main(void)
{
  int n;
  while(cin >> n && n)
    {
      vector<pair<int,int>> teams;
      for(int i=0;i<n;i++)
	{
	  int id,m1,s1,m2,s2,m3,s3,m4,s4;
	  cin >> id >> m1 >> s1 >> m2 >> s2 >> m3 >> s3 >> m4 >> s4;
	  teams.push_back(make_pair(60*(m1+m2+m3+m4)+(s1+s2+s3+s4),id));
	}
      sort(teams.begin(),teams.end());
      for(int i=0;i<n;i++)
	{
	  if(i==0 || i==1 || i==n-2)
	    {
	      cout << teams[i].second << endl;
	    }
	}
    }
  return 0;
}
accuracy: 1
time_ms: 10
memory_kb: 3188
final_rank: 9

code_snippet: #include <iostream>
#include <algorithm>
#include <vector>
#include <utility>
using namespace std;
int main(){
  int n;
  while(cin >> n, n){
    vector<pair<int,string>> V;
    for(int i = 0; i < n; ++i){
      string id;
      cin >> id;
      int t = 0;
      for(int i = 0; i < 4; ++i){
        int m, s;
        cin >> m >> s;
        t += m*60 + s;
      }
      V.emplace_back(t,id);
    }
    sort(V.begin(),V.end());
    cout << V[0].second << endl;
    cout << V[1].second << endl;
    cout << V[n-2].second << endl;
  }
}
accuracy: 1
time_ms: 10
memory_kb: 3404
final_rank: 15

code_snippet: #define _CRT_SECURE_NO_WARNINGS
#include "bits/stdc++.h"
using namespace std;
#define rep(i, n) for(int i=0; i<(n); ++i)
#define FOR(i, m, n) for(int i=(m); i<(n); ++i)
#define sz(x) ((int)(x).size())
#define all(x) (x).begin(),(x).end()
#define mp make_pair
#define pb push_back
#define Cout(x) cout << (x) << endl
#define Cout2(x, y) cout << (x) << " " << (y) << endl
#define dump(x) cout << #x << " = " << (x) << endl;
#define forauto(i, a) for(auto i : a)cout << i << " "; puts("");
typedef long long LL;
typedef vector<int> VI;
typedef vector<LL> VL;
typedef vector<string> VS;
typedef vector<bool> VB;
typedef vector<vector<int>> VVI;
typedef pair<int, int> PII;
const int inf = 1e9;
const double pi = acos(-1.0);

int main() {
	int n;
	while (cin >> n && n) {

		vector<PII> data(n);
		rep(i, n) {
			int id; cin >> id;
			int sec = 0;
			rep(i, 4) {
				int m, s; cin >> m >> s; sec += m * 60 + s;
			}
			data[i] = mp(sec, id);
		}

		sort(all(data));
		cout << data[0].second << endl << data[1].second << endl << data[sz(data) - 2].second << endl;
	}
}
accuracy: 1
time_ms: 10
memory_kb: 3044
final_rank: 2

code_snippet: #include <iostream>
#include <algorithm>

using namespace std;

struct Team {
	int num;
	int min[4];
	int s[4];
	int total;
};

int compute(Team group);
bool compare(Team i, Team j) {
	return (i.total < j.total);
}

int main() {

	int n;
	while (cin >> n && n != 0) {

		Team *group = new Team[n];

		for (int i = 0; i < n; i++) {

			cin >> group[i].num;

			for (int j = 0; j < 4; j++)
				cin >> group[i].min[j] >> group[i].s[j];

			group[i].total = compute(group[i]);
		}

		sort(group, group + n, compare);
		cout << group[0].num << "\n"
			 << group[1].num << "\n"
			 << group[n - 2].num<< "\n";
	}

	

	return 0;

}

int compute(Team group) {

	int total = 0;
	for (int i = 0; i < 4; i++)
		total += (group.min[i] * 60 + group.s[i]);

	return total;
}
accuracy: 1
time_ms: 10
memory_kb: 3460
final_rank: 17

code_snippet: #include<iostream>
using namespace std;

int main()
{
    int a[100000], sum[100000], b, c, n;

    while( cin >> n )
    {
        if( n == 0 )
            break;

        for( int i = 0; i < 100000; i++ )
            sum[i] = 0;

        for( int i = 0; i < n; i++ )
        {
            cin >> a[i];
            for( int j = 0; j < 4; j++ )
            {
                cin >> b >> c;
                sum[i] += b * 60 + c;
            }
        }

        for( int j = 0; j < 2; j++ )
        {
            int min = 1000000, max = 0, s = 0, t = 0;
            for( int i = 0; i < n; i++ )
            {
                if( a[i] != -1 && min > sum[i] )
                {
                    min = sum[i];
                    s = i;
                }
                if( a[i] != -1 && max < sum[i] )
                {
                    max = sum[i];
                    t = i;
                }
            }
            cout << a[s] << endl;
            if( j == 1 )
                cout << a[t] << endl;
            a[s] = -1;
            a[t] = -1;
        }
    }
    return 0;
}
accuracy: 1
time_ms: 10
memory_kb: 3512
final_rank: 18

code_snippet: #include<iostream>
#include<vector>
#include<algorithm>
#include<cctype>
#include<utility>
#include<string>
#include<cmath>
#include <numeric>
#include<map>
#include<cstdio>
 
 
#define REP(i, n) for(int i = 0;i < n;i++)
#define REPR(i, n) for(int i = n;i >= 0;i--)
#define FOR(i, m, n) for(int i = m;i < n;i++)
#define FORR(i, m, n) for(int i = m;i >= n;i--)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define llong long long
#define pb(a) push_back(a)
#define INF 1e13
using namespace std;
typedef pair<int, int> P;
typedef pair<llong, llong> LP;
typedef pair<int, P> PP;
typedef pair<llong, LP> LPP;
 
typedef long long int ll;
#define MOD 1000000007

bool comp(const pair<string,int>& p,const pair<string,int>& q){
    return p.second > q.second;
  }

int main(){

    int n;
    while(cin >> n,n){

        
        vector<P> arr;
        int id,m1,s1,m2,s2,m3,s3,m4,s4;
        REP(i,n){
            int tmp = 0;
            cin >> id >> m1 >> s1 >> m2 >> s2 >> m3 >> s3 >> m4 >> s4;
            tmp = 60*m1 + s1 + 60*m2 + s2 +60*m3 + s3 +60*m4 + s4;
            arr.pb(make_pair(tmp,id));
        }
        VSORT(arr);
        cout << arr[0].second << endl;
        cout << arr[1].second << endl;
        cout << arr[arr.size()-2].second << endl;
    }

    return 0;
}
accuracy: 1
time_ms: 10
memory_kb: 3172
final_rank: 7

code_snippet: #include<bits/stdc++.h>
using namespace std;

typedef long long ll;

struct hoge{
    ll s, n;
    hoge(ll s, ll n) : s(s), n(n) { }
};
bool operator < (const hoge &a, const hoge &b){
    return a.n != b.n ? a.n < b.n : a.s < b.s;
}

int main(void){
    while(true){
        ll n;
        cin >> n;
        if(n==0) break;
        vector<hoge> v;
        ll id, m1, s1, m2, s2, m3, s3, m4, s4;
        
        for(ll i=0; i<n; i++){
            cin >> id >> m1 >> s1 >> m2 >> s2 >> m3 >> s3 >> m4 >> s4;
            ll sum=60*m1+s1+60*m2+s2+60*m3+s3+60*m4+s4;
            v.push_back(hoge(id, sum));
        }
        sort(v.begin(), v.end());
        
        cout << v[0].s << "\n";
        cout << v[1].s << "\n";
        cout << v[n-2].s << "\n";
         
    }
     
     
    return 0;
}
accuracy: 1
time_ms: 10
memory_kb: 3204
final_rank: 11