Submission #238193

# Submission time Handle Problem Language Result Execution time Memory
238193 2020-06-10T07:16:10 Z NONAME Hokej (COCI17_hokej) C++17
84 / 120
190 ms 13308 KB
#include <bits/stdc++.h>
#define all(x) x.begin(), x.end()
#define sz(x) int(x.size())
#define el '\n'
#define pb push_back
#define mp make_pair
#define ft first
#define sd second
using namespace std;

typedef long long ll;

const int N = 5e5 + 10;

int n, m, ans, ps[N], a[N], b[N], ost[N], start[N];
vector <pair <int, pair <int, int> > > res;

bool cmp0(int x, int y) { return a[x] > a[y]; }
bool cmp1(int x, int y) { return b[x] > b[y]; }

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

    cin >> m >> n;
    for (int i = 0; i < n; ++i) {
        cin >> a[i] >> b[i];
        ost[i] = b[i];
        ps[i] = i;
    }

    sort(ps, ps + n, cmp0);

    int p = 0;

    for (int team = 0; team < 6; ++team) {
        int cur = 0;
        while (cur < m) {
            int o = min(m - cur, ost[ps[p]]);

            ost[ps[p]] -= o;
            ans += o * a[ps[p]];

            p += !ost[ps[p]];

            cur += o;
        }
    }

    if (!(p == n || b[ps[p]] == ost[ps[p]])) {
        b[ps[p]] -= ost[ps[p]];
        p++;
    }

    sort(ps, ps + p, cmp1);

    p = 0;

    for (int t = 0; t < 6; ++t) {
        start[t] = ps[p] + 1;
        int cur = b[ps[p]], lst = ps[p++];

        while (cur < m) {
            int o = min(m - cur, b[ps[p]]);

            b[ps[p]] -= o;
            res.pb(mp(cur, mp(lst + 1, ps[p] + 1)));
            lst = ps[p];

            p += !b[ps[p]];

            cur += o;
        }
    }

    sort(all(res));

    cout << ans << el;
    for (int i = 0; i < 6; ++i)
        cout << start[i] << ' ';
    cout << el << sz(res) << el;
    for (int i = 0; i < sz(res); ++i)
        cout << res[i].ft << ' ' << res[i].sd.ft << ' ' << res[i].sd.sd << el;
}
# Verdict Execution time Memory Grader output
1 Correct 5 ms 384 KB Output is correct
2 Correct 6 ms 512 KB Output is correct
3 Failed 13 ms 1024 KB the answer doesn't match with the value Z
4 Correct 5 ms 384 KB Output is correct
5 Correct 9 ms 640 KB Output is correct
6 Correct 6 ms 512 KB Output is correct
7 Correct 7 ms 640 KB Output is correct
8 Correct 38 ms 2936 KB Output is correct
9 Failed 190 ms 13308 KB the answer doesn't match with the value Z
10 Failed 190 ms 13224 KB the answer doesn't match with the value Z