# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
55553 | IvanC | Hokej (COCI17_hokej) | C++17 | 244 ms | 18592 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
using namespace std;
typedef tuple<int,int,int> trinca;
typedef pair<int,int> ii;
typedef long long ll;
const int MAXN = 5*1e5 + 10;
vector<trinca> guloso,substituicoes;
vector<ii> greedy;
vector<int> escolhidos;
int qual[6][MAXN],N,M;
ll Z;
int main(){
scanf("%d %d",&M,&N);
for(int i = 1;i<=N;i++){
int qualidade,dura;
scanf("%d %d",&qualidade,&dura);
guloso.push_back(make_tuple(qualidade,dura,i));
}
sort(guloso.begin(),guloso.end());
int T_total = 6*M;
while(T_total > 0){
trinca davez = guloso.back();
guloso.pop_back();
int valor = get<0>(davez), tempo = get<1>(davez),identificacao = get<2>(davez);
tempo = min(min(tempo,T_total),M);
T_total -= tempo;
Z += 1LL*valor*tempo;
greedy.push_back(ii(tempo,identificacao));
}
guloso.clear();
sort(greedy.begin(),greedy.end());
for(int linha = 0;linha<6;linha++){
for(int instante = 1;instante<=M;instante++){
qual[linha][instante] = greedy.back().second;
greedy.back().first--;
if(greedy.back().first == 0) greedy.pop_back();
}
}
for(int linha = 0;linha<6;linha++) escolhidos.push_back(qual[linha][1]);
sort(escolhidos.begin(),escolhidos.end());
for(int instante = 1;instante<M;instante++){
for(int linha = 0;linha<6;linha++){
if(qual[linha][instante] != qual[linha][instante+1]){
substituicoes.push_back(make_tuple(instante,qual[linha][instante],qual[linha][instante+1]));
}
}
}
printf("%lld\n",Z);
for(int i : escolhidos) printf("%d ",i);
printf("\n");
printf("%d\n",(int)substituicoes.size());
for(trinca davez : substituicoes){
printf("%d %d %d\n",get<0>(davez),get<1>(davez),get<2>(davez));
}
return 0;
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |