坑点太多了,建议看晴神和柳神算法,自己debug搞了好久,最后一个测试点还是没过,准备今天晚上重写一遍,坑到想流泪😭
#include<cstdio>
#include<iostream>
#include<algorithm>
#include<string.h>
#include<vector>
using namespace std;
const int maxn=10010;
struct node
{
int id;
int total,score[6];
int flag;
}a[maxn];
bool cmp(node b,node c)
{
if (b.total!=c.total)return b.total>c.total;
else if (b.score[0]!=c.score[0])return b.score[0]>c.score[0];
else return b.id<c.id;
}
int main()
{
int n,k,m;
cin>>n>>k>>m;
vector<int> max1(k+1);
for (int i=1;i<=k;i++)
{
scanf("%d",&max1[i]);
}
for (int i=1;i<=n;i++)
{
for (int j=0;j<k+1;j++)
{
a[i].score[j]=-1;
}
a[i].total=0;
a[i].flag=0;
}
for (int i=0;i<m;i++)
{
int id,num,score;
scanf("%d %d %d",&id,&num,&score);
a[id].id=id;
if(a[id].score[num]==-1)
{
a[id].score[num]=0;
}
if (score>=a[id].score[num]&&score<=max1[num])
{
a[id].total-=a[id].score[num];
a[id].score[num]=score;
a[id].total+=a[id].score[num];
if(a[id].score[num]==max1[num])
{
a[id].score[0]++;
}
a[id].flag=1;
}
}
a[0].total=-1;
sort(a,a+n+1,cmp);
int rank=1;
for (int i=0;i<n;i++)
{
if(a[i].flag==1)
{
if (i==0)
printf("%d",rank);
else if (a[i].total==a[i-1].total)
{
rank--;
printf("%d",rank);
}
else
{
printf("%d",i+1);
}
printf(" %05d %d",a[i].id,a[i].total);
for (int j=1;j<=k;j++)
{
if(a[i].score[j]==-1)
printf(" -");
else
printf(" %d",a[i].score[j]);
}
printf("\n");
rank++;
}
}
}
/*2 3 4
20 30 40
1 1 15
1 3 20
2 3 0
2 2 0*/