L2-009 抢红包

#include <bits/stdc++.h>

using namespace std;

int main() {
    int n;
    cin >> n;
    struct p { int id, money, cnt;};
    vector<p> person(n + 1);
    for (int i = 1; i <= n; i++) person[i] = {i, 0, 0};
    for (int i = 1; i <= n; i++) {
        int k;
        cin >> k;
        int curF = 0;
        for (int j = 0; j < k; j++) {
            int num, p;
            cin >> num >> p;
            curF += p;
            person[num].money += p;
            person[num].cnt++;
        }
        person[i].money -= curF;
    }

    sort(person.begin() + 1, person.end(), [&](p x, p y){
        if (x.money != y.money) return x.money > y.money;
        else {
            if (x.cnt != y.cnt) return x.cnt > y.cnt;
            else return x.id < y.id;
        }
    });

    for (int i = 1; i < person.size(); i++) {
        cout << person[i].id << " " << fixed << setprecision(2) << 1.0 * person[i].money / 100 << "\n"[i == person.size() - 1];
    }

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