【出分前夕】怎搞呢,难的题不会写,简单的题就算多花点时间也要写出来

#include <cstdio>
#include <algorithm>
#include <string>
#include <vector>
using namespace std;

struct Stu {
    string id;   // 学号
    int grade;   // 成绩
};

// 比较函数:先按成绩降序,成绩相同则按学号升序
bool cmp(const Stu &lhs, const Stu &rhs) {
    if (lhs.grade == rhs.grade) {
        return lhs.id < rhs.id;
    }
    return lhs.grade > rhs.grade;
}

// 4 5 25 4个人,5道考题,分数线是25
// 10 10 12 13 15 1~5题每题的分值
// CS004 3 5 1 3 学号 解决了3道题,分别是第5题,第1题和第3题
// CS003 5 2 4 1 3 5
// CS002 2 1 2
// CS001 3 2 3 5
int main() {
    int N, M, G; // N位考生,M道题,分数线G
    while (scanf("%d", &N) != EOF) {
        if (N == 0) break; // 输入结束

        scanf("%d%d", &M, &G);
        vector<int> scores(M + 1); // 存储每道题的分值,从1开始编号
        for (int i = 1; i <= M; i++) {
            scanf("%d", &scores[i]);
        }

        vector<Stu> students; // 存储学生信息
        for (int i = 0; i < N; i++) {
            char id[30];
            int solved;
            scanf("%s%d", id, &solved);
            int total = 0;
            for (int j = 0; j < solved; j++) {
                int problem;
                scanf("%d", &problem);
                total += scores[problem]; // 累加成绩
            }
            students.push_back({ id, total }); // 存储学生信息
        }

        // 按成绩降序排序,成绩相同则按学号升序
        sort(students.begin(), students.end(), cmp);

        // 统计通过分数线的人数
        int cnt = 0;
        for (const Stu &stu : students) {
            if (stu.grade >= G) {
                cnt++;
            }
            else {
                break; // 后续学生成绩更低,无需继续检查
            }
        }

        // 输出结果
        printf("%d\n", cnt);
        for (int i = 0; i < cnt; i++) {
            printf("%s %d\n", students[i].id.c_str(), students[i].grade);
        }
    }
    return 0;
}