# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
381038 | IldarKA | Hokej (COCI17_hokej) | C++14 | 342 ms | 6636 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;
int m, n, k[500001], l[500001], id[500001];
bool cmp(int a, int b){
return k[a] > k[b];
}
vector < pair < int, pair < int, int > > > v3;
vector < int > v2;
int main(){
cin >> m >> n;
for(int i = 1; i <= n; i++){
cin >> k[i] >> l[i];
id[i] = i;
}
sort(id + 1, id + 1 + n, &cmp);
vector < pair < int, int > > v;
int kol = m * 6;
long long ans = 0;
for(int i = 1; i <= n; i++){
if(l[id[i]] <= kol){
v.push_back({l[id[i]], id[i]});
ans += l[id[i]] * 1ll * k[id[i]];
kol -= l[id[i]];
}
else if(kol > 0){
v.push_back({kol, id[i]});
ans += kol * 1ll * k[id[i]];
kol = 0;
}
}
sort(v.begin(), v.end());
cout << ans << '\n';
kol = m;
int row = 1;
int pos = (int)v.size() - 1;
int last = -1;
while(row < 7){
if(kol >= v[pos].first){
if(last == -1){
kol -= v[pos].first;
last = v[pos].second;
v2.push_back(last);
}
else{
v3.push_back({m - kol, {last, v[pos].second}});
kol -= v[pos].first;
last = v[pos].second;
}
}
else{
v3.push_back({m - kol, {last, v[pos].second}});
kol = m + kol - v[pos].first;
last = v[pos].second;
v2.push_back(last);
row++;
}
if(kol == 0){
row++;
kol = m;
last = -1;
}
pos--;
}
for(int i = 0; i < v2.size(); i++){
cout << v2[i] << " ";
}
cout << '\n';
sort(v3.begin(), v3.end());
cout << v3.size() << '\n';
for(int i = 0; i < v3.size(); i++){
cout << v3[i].first << " " << v3[i].second.first << " " << v3[i].second.second << '\n';
}
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |