B1004 成绩排名 struct排序问题

想知道这段为什么会错误

 #include <iostream>
#include <algorithm>
using namespace std;

struct stu
{
    string Name;
    int Score;
};

void cmp(stu s1, stu s2)
{
    if (s1.Score != s2.Score) 
    {
        s1.Score < s2.Score;
    }
}

int main()
{
    int n;
    cin >> n;
    string name;
    int id;
    int score;
    stu a[10000];

    while (n--)
    {
        cin >> name >> id >> score;
        a[id].Name = name;
        a[id].Score = score;
    }
    sort(a, a+n);
    cout << a[0].Name << " " << a[0].Score << endl;
    cout << a[n-1].Name << " " << a[n-1].Score; 
}

int id;修改为
int id = 0;
a[id].Name = name;
a[id].Score = score;
后面加上
id++;