Submission #403321

#TimeUsernameProblemLanguageResultExecution timeMemory
403321penguinhackerHokej (COCI17_hokej)C++14
120 / 120
196 ms35220 KiB
#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)

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 timeMemoryGrader output
Fetching results...