# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
403321 | penguinhacker | Hokej (COCI17_hokej) | C++14 | 196 ms | 35220 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;
#define ll long long
#define ar array
const int mxN=5e5;
int n, m, cur;
ll ans;
ar<int, 3> a[mxN];
vector<int> in[mxN+1], out[mxN+1];
vector<ar<int, 3>> upd;
void add(int l, int r, int i, int x) {
in[l].push_back(i);
out[r].push_back(i);
cur+=r-l;
ans+=(ll)(r-l)*x;
//cout << l << " " << r << " " << x << endl;
}
int main() {
ios::sync_with_stdio(0);
cin.tie(0);
cin >> m >> n;
for (int i=0; i<n; ++i)
cin >> a[i][0] >> a[i][1], a[i][2]=i;
sort(a, a+n);
for (int i=n-1; ~i; --i) {
int c=a[i][0], t=a[i][1], ind=a[i][2];
if (t==m) {
if (cur<5*m) {
add(0, m, ind, c);
} else {
add(cur%m, m, ind, c);
break;
}
//cout << cur << endl;
continue;
}
if (cur+t>=6*m) {
add(cur%m, m, ind, c);
break;
}
if (cur%m+t>=m) {
t-=m-cur%m;
add(cur%m, m, ind, c);
}
if (t)
add(cur%m, cur%m+t, ind, c);
//cout << cur << endl;
}
assert(in[0].size()==6);
for (int i=1; i<m; ++i) {
assert(in[i].size()==out[i].size());
for (int j=0; j<in[i].size(); ++j)
upd.push_back({i, out[i][j], in[i][j]});
}
cout << ans << "\n";
for (int i : in[0])
cout << i+1 << " ";
cout << "\n" << upd.size() << "\n";
for (ar<int, 3> x : upd)
cout << x[0] << " " << x[1]+1 << " " << x[2]+1 << "\n";
return 0;
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |