Submission #136570

# Submission time Handle Problem Language Result Execution time Memory
136570 2019-07-25T15:01:07 Z mariusnicoli Hokej (COCI17_hokej) C++14
60 / 120
547 ms 6520 KB
#include <iostream>
#include <algorithm>

using namespace std;

struct player {
    int value;
    int resistence;
    int position;
};

struct ch {
    int minute;
    int enter;
    int exit;
};

player v[500010];
ch Change[1000001];
int Start[7];

int change, start, n, m, rest, lin, col, i, j, sol, last;

int cmp(const player &a, const player &b) {
    if (a.value != b.value)
        return a.value > b.value;
    else
        return a.resistence > b.resistence;
}

int cmp1(const ch &a, const ch &b) {
    return a.minute < b.minute;
}

int main () {
    cin>>m>>n;
    for (i=1;i<=n;i++) {
        cin>>v[i].value>>v[i].resistence;
        v[i].position = i;
    }

    sort(v+1, v+n+1, cmp);
/**
    for (i=1;i<=n;i++) {
        cout<<v[i].value<<" "<<v[i].resistence<<" "<<v[i].position<<"\n";
    }
**/
    for (i=1;i<=6;i++) {
        if (v[i].resistence < m) {
            break;
        }
        Start[i] = v[i].position;
        start = i;
        sol += v[i].value * m;
    }
    rest = 6*m - (i-1)*m;
    last = -1;

    col = 1;

    for (j=i;j<=n;j++) {
        if (col == 1) {
            start++;
            Start[start] = v[j].position;
        }

        if (last != -1) {
            Change[++change].minute = col;
            Change[change].enter = v[j].position;
            Change[change].exit = last;
        }
        last = v[j].position;

        if (rest <= v[j].resistence) {
            sol += rest * v[j].value;
            break;
        }else {
            if (col + v[j].resistence <= m) {
                col += v[j].resistence;
            } else
                if (col + v[j].resistence == m+1) {
                    last =-1;
                    col = 1;
                } else {
                    Start[++start] = v[j].position;
                    col = v[j].resistence - (m-col);
                }
            rest -= v[j].resistence;
            sol += v[j].resistence * v[j].value;
        }
    }

    sort(Change+1, Change+change+1, cmp1);
    cout<<sol<<"\n";
    for (i=1;i<=6;i++)
        cout<<Start[i]<<" ";
    cout<<"\n";
    cout<<change<<"\n";
    for (i=1;i<=change;i++)
        cout<<Change[i].minute-1<<" "<<Change[i].exit<<" "<<Change[i].enter<<"\n";
    return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 3 ms 376 KB Output is correct
2 Correct 8 ms 376 KB Output is correct
3 Failed 29 ms 632 KB the answer doesn't match with the value Z
4 Correct 2 ms 376 KB Output is correct
5 Correct 11 ms 504 KB Output is correct
6 Correct 5 ms 376 KB Output is correct
7 Incorrect 10 ms 504 KB Output isn't correct
8 Incorrect 93 ms 1656 KB Output isn't correct
9 Incorrect 547 ms 6452 KB Output isn't correct
10 Incorrect 531 ms 6520 KB Output isn't correct