Submission #82886

# Submission time Handle Problem Language Result Execution time Memory
82886 2018-11-02T15:03:15 Z Milki Hokej (COCI17_hokej) C++14
120 / 120
171 ms 6908 KB
#include <bits/stdc++.h>
using namespace std;

#define FOR(i, a, b) for(int i = (a); i < (b); ++i)
#define REP(i, n) FOR(i, 0, n)
#define _ << " " <<
#define sz(x) (int)x.size()
#define pb(x) push_back(x)

typedef long long ll;
typedef pair<int, int> point;

struct igrac{
    int k = 0, i = 0, id = 0;
    igrac(int _k, int _i, int _id){
        k = _k; i = _i; id = _id;
    }

    friend bool operator < (const igrac A, const igrac B){
        return A.k > B.k;
    }
};

vector <igrac> v, zamjene;
vector <int> postava[6];
int n, m;
int tijme[6], start[6], bio[6];

bool cmp(igrac A, igrac B){
    return A.k < B.k;
}

int main(){
    ios_base::sync_with_stdio(false); cin.tie(0);
    cin >> n >> m;
    REP(i, m){
        int a, b; cin >> a >> b;
        v.pb(igrac(a, b, i + 1));
    }
    sort(v.begin(), v.end());

    ll sol = 0;
    int l = 0, r = 5;
    for(auto &it : v){
        if(l > r) break;
        if(it.i >= n && l != r){
            sol += (ll)n * it.k;
            postava[r].pb(it.id);
            r --;
        }
        else{
            int left = n - tijme[l];
            if(it.i >= left){
                sol += (ll)left * it.k;
                if(!postava[l].empty()) zamjene.pb(igrac(tijme[l], postava[l].back(), it.id));
                postava[l].pb(it.id);
                l ++;
                if(l > r) break;
                it.i -= left;
                if(it.i == 0) continue;
                tijme[l] += it.i;
                sol += (ll)it.i * it.k;
                postava[l].pb(it.id);
            }
            else{
                sol += (ll)it.i * it.k;
                if(!postava[l].empty()) zamjene.pb(igrac(tijme[l], postava[l].back(), it.id));
                postava[l].pb(it.id);
                tijme[l] += it.i;
            }
        }
    }
    sort(zamjene.begin(), zamjene.end(), cmp);

    cout << sol << "\n";
    REP(i, 6)
        cout << postava[i][0] << " ";
    cout << "\n";
    cout << sz(zamjene) << "\n";
    for(auto it : zamjene){
        cout << it.k _ it.i _ it.id << "\n";
    }
}

# Verdict Execution time Memory Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 4 ms 628 KB Output is correct
3 Correct 9 ms 1032 KB Output is correct
4 Correct 2 ms 1032 KB Output is correct
5 Correct 6 ms 1032 KB Output is correct
6 Correct 3 ms 1032 KB Output is correct
7 Correct 5 ms 1032 KB Output is correct
8 Correct 32 ms 2220 KB Output is correct
9 Correct 164 ms 6856 KB Output is correct
10 Correct 171 ms 6908 KB Output is correct