L2-027 名人堂与代金券

#include <bits/stdc++.h>

using namespace std;
using ll = long long;

int main() {
    int n, g, k;
    cin >> n >> g >> k;
    vector<tuple<string, int>> score(n);
    int sum = 0;
    for (int i = 0; i < n; i++) {
        string num;
        int s;
        cin >> num >> s;
        score[i] = {num, s};
        if (s >= g && s <= 100) sum += 50;
        else if (s >= 60 && s < g) sum += 20;
    }
    sort(score.begin(), score.end(), [&](tuple<string, int> x, tuple<string, int> y) {
        if (get<1>(x) != get<1>(y)) return get<1>(x) > get<1>(y);
        return get<0>(x) < get<0>(y);
    });
    vector<tuple<int, string, int>> res;
    int rank = 1, m = 0;
    for (int i = 0; i < score.size(); ++i) {
        int j = i;
        while (j < score.size() && get<1>(score[j]) == get<1>(score[j + 1])) {
            j++;
        } 
        for (int k = i; k <= j; k++) {
            res.push_back({rank, get<0>(score[k]), get<1>(score[i])});
        }
        rank += j - i + 1; 
        i = j;
    }
    cout << sum << "\n";
    for (int i = 0; i < res.size(); i++) {
        if (get<0>(res[i]) <= k) cout << get<0>(res[i]) << " " << get<1>(res[i]) << " " << get<2>(res[i]) << "\n";
    }

    return 0;
}
posted @ 2022-03-22 16:04  Xxaj5  阅读(20)  评论(0编辑  收藏  举报