Problem:
ICPC Ranking
Your mission in this problem is to write a program
which, given the submission log of an ICPC (International Collegiate Programming Contest),
determines team rankings.
The log is a sequence of records of program submission
in the order of submission.
A record has four fields: elapsed time, team number,
problem number, and judgment.
The elapsed time is the time elapsed from the beginning of the contest
to the submission.
The judgment field tells whether the submitted program was
correct or incorrect, and when incorrect,
what kind of an error was found.
The team ranking is determined according to the following rules.
Note that the rule set shown here is one used in the real ICPC World Finals and Regionals,
with some detail rules omitted for simplification.
Teams that solved more problems are ranked higher.
Among teams that solve the same number of problems, 
ones with smaller total consumed time are ranked higher.
If two or more teams solved the same number of problems, and their
total consumed times are the same, they are ranked the same.
The total consumed time is the sum of the consumed time for each problem solved.
The consumed time for a solved problem is the elapsed time 
of the accepted submission plus 20 penalty minutes for every previously rejected submission for that problem.
If a team did not solve a problem, the consumed time for the problem is zero, and thus even if there are several incorrect submissions, no penalty is given.
You can assume that a team never submits a program for a problem
after the correct submission for the same problem.
Input
The input is a sequence of datasets each in the following format.
The last dataset is followed by a line with four zeros.
M
T
P
R
m
1
t
1
p
1
j
1
m
2
t
2
p
2
j
2
.....
m
R
t
R
p
R
j
R
The first line of a dataset contains four integers
M
,
T
,
P
, and
R
.
M
is the duration of the contest.
T
is the number of teams.
P
is the number of problems.
R
is the number of submission records.
The relations 
120 ≤
M
≤ 300,
1 ≤
T
≤ 50,
1 ≤
P
≤ 10,
and 0 ≤
R
≤ 2000
hold for these values.
Each team is assigned a team number between 1 and
T
, inclusive.
Each problem is assigned a problem number between 1 and
P
, inclusive.
Each of the following
R
lines contains a submission record
with four integers
m
k
,
t
k
,
p
k
, and
j
k
(1 ≤
k
≤
R
).
m
k
is the elapsed time.
t
k
is the team number.
p
k
is the problem number.
j
k
is the judgment
(0 means correct, and other values mean incorrect).
The relations
0 ≤
m
k
≤
M
−1,
1 ≤
t
k
≤
T
,
1 ≤
p
k
≤
P
,
and 0 ≤
j
k
≤ 10
hold for these values.
The elapsed time fields are rounded off to the nearest minute.
Submission records are given in the order of submission.
Therefore, if
i
<
j
,
the
i
-th submission is done before the
j
-th submission
(
m
i
≤
m
j
).
In some cases, you can determine the ranking of two teams
with a difference less than a minute, by using this fact.
However, such a fact is never used in the team ranking.
Teams are ranked only using time informa
...(truncated)

Submitted solutions:

code_snippet: #define  _CRT_SECURE_NO_WARNINGS
#include <stdio.h>
#include <algorithm>
#include <utility>
#include <functional>
#include <cstring>
#include <queue>
#include <stack>
#include <math.h>
#include <iterator>
#include <vector>
#include <string>
#include <set>
#include <math.h>
#include <iostream> 
#include <random>
#include<map>
#include <iomanip>
#include <time.h>
#include <stdlib.h>
#include <list>
#include <typeinfo>
#include <list>
#include <set>
#include <cassert>
#include<fstream>
#include <unordered_map>  
using namespace std;
#define Ma_PI 3.141592653589793
#define eps 0.00000000000000000000000001
#define LONG_INF 10000000000000000
#define GOLD 1.61803398874989484820458
#define MAX_MOD 1000000007
#define REP(i,n) for(long long i = 0;i < n;++i)
int main() {
#define int long long 
	while (true) {
		int m, t, p, r;
		cin >> m >> t >> p >> r;
		int penalty[1000][1000] = {};
		tuple<int, int, int> team_info[1000] = {};
		if (m == 0) return 0;
		REP(i, r) {
			int a, b, c, d;
			cin >> a >> b >> c >> d;
			if (d == 0) {
				//Accepted
				get<0>(team_info[b]) += 1;//AC counter up
				get<2>(team_info[b]) += penalty[c][b];
				get<1>(team_info[b]) += a + penalty[c][b] * 20;
			}
			else {
				penalty[c][b]++;
			}
		}
		vector<tuple<int, int, int>> sortings;//AC,Time,number
		for (int i = 1; i <= t; ++i) {
			sortings.push_back(make_tuple(get<0>(team_info[i]), get<1>(team_info[i]) * -1, i));
		}
		sort(sortings.begin(), sortings.end(), greater<tuple<int, int, int>>());
		queue<int> teaming;
		pair<int, int> now_back = make_pair(-1, -1);
		for (int i = 0; i < sortings.size(); ++i) {
			if (now_back == make_pair(get<0>(sortings[i]), get<1>(sortings[i]))) {
				teaming.push(get<2>(sortings[i]));
			}
			else {
				if (teaming.empty() == false) {
					int ok = 1;
					while (teaming.empty() == false) {
						if (ok == 0) {
							cout << "=";
						}
						ok = 0;
						cout << teaming.front();
						teaming.pop();
					}
					cout << ",";
				}
				teaming.push(get<2>(sortings[i]));
				now_back = make_pair(get<0>(sortings[i]), get<1>(sortings[i]));
			}
		}
		if (teaming.empty() == false) {
			int ok = 1;
			while (teaming.empty() == false) {
				if (ok == 0) {
					cout << "=";
				}
				ok = 0;
				cout << teaming.front();
				teaming.pop();
			}
		}
		cout << endl;
	}
}
accuracy: 1
time_ms: 10
memory_kb: 10920
final_rank: 2

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

using namespace std;

int M,T,P,R;
int m[2000],t[2000],p[2000],j[2000];
struct team{
	int n,s,t,w[2000];
};

bool comp(const team &t1,const team &t2){
	if(t1.t==t2.t && t1.s==t2.s)return t1.n>t2.n;
	if(t1.s==t2.s)return t1.t<t2.t;
	return t1.s>t2.s;
};

team dat[2001];

int main(void){
	while(1){
		scanf("%d%d%d%d",&M,&T,&P,&R);
		if(M+T+R+P==0)break;
		memset(dat,0,sizeof(dat));
		for(int i=0;i<T;i++)dat[i].n=i+1;
		for(int i=0;i<R;i++){
			scanf("%d%d%d%d",&m[i],&t[i],&p[i],&j[i]);
			if(j[i]!=0){
				dat[t[i]-1].w[p[i]]++;
			}else{
				dat[t[i]-1].s++;
				dat[t[i]-1].t+=m[i]+dat[t[i]-1].w[p[i]]*20;
			}
		}
		sort(dat,dat+T,comp);
		printf("%d",dat[0].n);
		for(int i=1;i<T;i++){
			if(dat[i-1].s==dat[i].s && dat[i-1].t==dat[i].t)printf("=");
			else printf(",");
			printf("%d",dat[i].n);
		}
		printf("\n");
	}
	return 0;
}
accuracy: 1
time_ms: 50
memory_kb: 18884
final_rank: 3

code_snippet: #include<iostream>
#include<algorithm>
#include<vector>
using namespace std;
struct team{
	int num,p,cnt;
	int w[11];
	void init(int n)
	{
		num=n;
		p=0;
		cnt=0;
		for(int i=0;i++<10;)w[i]=0;
	}
	void submit(int m,int i,int j)
	{
		if(j)w[i]++;
		else p+=m+w[i]*20,cnt++;
	}
	bool operator<(team a)
	{
		if(cnt!=a.cnt)return cnt>a.cnt;
		else if(p!=a.p)return p<a.p;
		else return num>a.num;
	}
	bool operator==(team a)
	{
		return cnt==a.cnt&&p==a.p;
	}
};
int M,T,P,R;
main()
{
	while(cin>>M>>T>>P>>R,M)
	{
		team a[55];
		for(int i=0;i++<T;)a[i].init(i);
		for(int i=0;i<R;i++)
		{
			int b,c,d,e;cin>>b>>c>>d>>e;
			a[c].submit(b,d,e);
		}
		sort(a+1,a+T+1);
		for(int i=0;i++<T;)
		{
			if(i==1)cout<<a[i].num;
			else
			{
				cout<<(a[i-1]==a[i]?"=":",")<<a[i].num;
			}
		}
		cout<<endl;
	}
}
accuracy: 1
time_ms: 10
memory_kb: 3152
final_rank: 1