Submission #991993

# Submission time Handle Problem Language Result Execution time Memory
991993 2024-06-03T14:00:57 Z theboatman Hokej (COCI17_hokej) C++17
120 / 120
99 ms 30288 KB
#include <bits/stdc++.h>

using namespace std;

struct Player {
    int power;
    int stamina;
    int id;
};

struct Swap {
    int time;
    int from;
    int to;
};

void solve() {
    int m, n;
    cin >> m >> n;

    vector <Player> players(n);
    for (int i = 0; i < n; i++) {
        cin >> players[i].power >> players[i].stamina;
        players[i].id = i;
    }

    sort(players.begin(), players.end(), [](const Player &a, const Player &b) {
        return a.power > b.power;
    });

    int ykFree = 0;
    vector <int> a(6 * m);
    long long sum = 0;
    for (auto player : players) {
        while(ykFree < 6 * m && player.stamina) {
            player.stamina--;
            a[ykFree] = player.id;
            sum += player.power;

            ykFree++;
        }
    }
    vector <int> startTeam(6);
    for (int i = 0; i < 6; i++) {
        startTeam[i] = a[i * m];
    }

    vector <vector <pair <int, int> > > op(m);
    for (int i = 0; i < 6 * m; i++) {
        if (i % m == 0) {
            continue;
        }

        if (a[i - 1] != a[i]) {
            op[i % m - 1].push_back({a[i - 1], a[i]});
        }

    }

    vector <Swap> swaps;
    for (int t = 0; t < m; t++) {
        map <int, int> in, to;
        for (auto i : op[t]) {
            in[i.second]++;
            to[i.first] = i.second;
        }

        for (auto i : to) {
            if (in[i.first] == 0) {
                int start = i.first;
                int x = start;
                while(to.find(start) != to.end()) {
                    start = to[start];
                }
                int y = start;

                swaps.push_back({t, x, y});
            }
        }
    }


    cout << sum << "\n";
    for (auto i : startTeam) {
        cout << i + 1 << " ";
    }
    cout << "\n";

    cout << swaps.size() << "\n";
    for (auto i : swaps) {
        cout << i.time + 1 << " " << i.from + 1 << " " << i.to + 1 << "\n"; 
    }
} 

int main() {
    cin.tie(0);
    ios::sync_with_stdio(0);

    solve();
}
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 2 ms 604 KB Output is correct
3 Correct 19 ms 24260 KB Output is correct
4 Correct 1 ms 344 KB Output is correct
5 Correct 8 ms 10072 KB Output is correct
6 Correct 1 ms 344 KB Output is correct
7 Correct 2 ms 600 KB Output is correct
8 Correct 17 ms 4444 KB Output is correct
9 Correct 94 ms 30120 KB Output is correct
10 Correct 99 ms 30288 KB Output is correct