#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
hokej.cpp: In function 'int main()':
hokej.cpp:56:18: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
56 | for (int j=0; j<in[i].size(); ++j)
| ~^~~~~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
13 ms |
23756 KB |
Output is correct |
2 |
Correct |
15 ms |
23952 KB |
Output is correct |
3 |
Correct |
25 ms |
24396 KB |
Output is correct |
4 |
Correct |
13 ms |
23756 KB |
Output is correct |
5 |
Correct |
21 ms |
24148 KB |
Output is correct |
6 |
Correct |
15 ms |
23884 KB |
Output is correct |
7 |
Correct |
16 ms |
23884 KB |
Output is correct |
8 |
Correct |
58 ms |
26264 KB |
Output is correct |
9 |
Correct |
190 ms |
34944 KB |
Output is correct |
10 |
Correct |
196 ms |
35220 KB |
Output is correct |