Submission #142468

# Submission time Handle Problem Language Result Execution time Memory
142468 2019-08-09T06:28:05 Z RobertDobra Hokej (COCI17_hokej) C++14
120 / 120
531 ms 17092 KB
#include <iostream>
#include <algorithm>
#include <deque>

using namespace std;

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

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

player v[500010];
ch Change[1000001];
deque<long long> Start;

long long 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);
    rest = 6*m;
    col = 1;
    last = -1;
    for (j=1;j<=n;j++) {
        if (v[j].resistence == m) {
            if (rest >= m) {
                Start.push_front(v[j].position);
                rest -= m;
                sol += v[j].value * m;
                if (rest == 0)
                    break;
                else
                    continue;
            }
        }
        if (col == 1) 
            Start.push_back(v[j].position);
        if (col != 1) {
            change++;
            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.push_back(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.front()<<" ";
        Start.pop_front();
    }
    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 2 ms 376 KB Output is correct
2 Correct 8 ms 504 KB Output is correct
3 Correct 30 ms 1144 KB Output is correct
4 Correct 3 ms 376 KB Output is correct
5 Correct 12 ms 632 KB Output is correct
6 Correct 5 ms 504 KB Output is correct
7 Correct 10 ms 632 KB Output is correct
8 Correct 94 ms 3720 KB Output is correct
9 Correct 531 ms 17092 KB Output is correct
10 Correct 520 ms 12636 KB Output is correct