时间限制: 1 Sec 内存限制: 128 MB
题目描述
There are N teams (numbered from 1 to N ) and M problems (numbered from 1 to N ) in this year’s ICPC. The j-th problem has Tj testcases. Surprisingly, every team submitted exactly one solution to every problem. The N -th team managed to solve Sij testcases on the N -th problem.
A team solved a problem only if the team managed to solve ALL testcases on that problem. The winning team is the team with the most number of problems solved. If there are more than one team with the most number of problems solved, then the winning team is the team with the smallest index among those teams.
Determine the index of the winning team.
输入
The first line contains two integers: N M (1 ≤ N ,M ≤ 100) in a line denoting the number of teams and the number of problems. The second line contains M integers: T1 T2…TM(0 ≤ Ti ≤ 100) in a line denoting the number of testcases. The next N following lines, each contains M integers; the j-th integer on the i-th line is Sij (0 ≤ Sij ≤ Tj ) denoting the number of solved testcases by the i-th team for the j-th problem.
输出
The output contains the index of the winning team, in a line.
样例输入
3 2
10 20
0 19
10 0
9 19
样例输出
2
提示
On the first sample, the first and the third team did not solve any problem, and the second team solved the first problem. Therefore, the second team is the winner.
#include<iostream>
#include<cstring>
#include<string>
#include<cstdio>
#include<algorithm>
#define ll long long
using namespace std;
const int N=105;
int n,m;
int stand[N];
struct node
{
int no,sol;
}ans[N];
bool cmp(node a,node b)
{
if(a.sol!=b.sol) return a.sol>b.sol;
return a.no<b.no;
}
int main()
{
scanf("%d%d",&n,&m);
for(int i=1;i<=m;i++) scanf("%d",&stand[i]);
for(int i=1;i<=n;i++)
{
for(int j=1;j<=m;j++)
{
int temp;
scanf("%d",&temp);
if(temp==stand[j]) ans[i].sol++;
}
ans[i].no=i;
}
sort(ans+1,ans+1+n,cmp);
printf("%d\n",ans[1].no);
}