# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
381036 |
2021-03-24T09:54:52 Z |
IldarKA |
Hokej (COCI17_hokej) |
C++14 |
|
351 ms |
11392 KB |
#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--;
}
cout << ans << '\n';
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
hokej.cpp: In function 'int main()':
hokej.cpp:66:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
66 | for(int i = 0; i < v2.size(); i++){
| ~~^~~~~~~~~~~
hokej.cpp:72:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, std::pair<int, int> > >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
72 | for(int i = 0; i < v3.size(); i++){
| ~~^~~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
OK |
1 ms |
364 KB |
Checker has crashed |
2 |
OK |
4 ms |
492 KB |
Checker has crashed |
3 |
Incorrect |
18 ms |
876 KB |
Expected int32, but "299047561386" found |
4 |
OK |
1 ms |
384 KB |
Checker has crashed |
5 |
OK |
7 ms |
620 KB |
Checker has crashed |
6 |
OK |
4 ms |
492 KB |
Checker has crashed |
7 |
OK |
7 ms |
492 KB |
Checker has crashed |
8 |
OK |
60 ms |
2668 KB |
Checker has crashed |
9 |
Incorrect |
351 ms |
11372 KB |
Expected int32, but "298674474813" found |
10 |
Incorrect |
339 ms |
11392 KB |
Expected int32, but "297203184231" found |