Submission #131751

#TimeUsernameProblemLanguageResultExecution timeMemory
131751IOrtroiiiNaan (JOI19_naan)C++14
100 / 100
624 ms118784 KiB
#include <bits/stdc++.h> using namespace std; using ll = long long; using Val = array<ll, 3>; bool cmp(Val l, Val r) { if (l[0] ^ r[0]) { return l[0] < r[0]; } else { return l[1] * r[2] < l[2] * r[1]; } } int main() { ios_base::sync_with_stdio(false); int n, l; cin >> n >> l; vector<vector<Val>> go(n); for (int i = 0; i < n; ++i) { ll sum = 0; vector<ll> a(l); for (int j = 0; j < l; ++j) { cin >> a[j]; sum += a[j]; } ll csum = 0; int cur = 0; for (int j = 1; j < n; ++j) { while (cur < l && (ll) (csum + a[cur]) * n <= sum * j) { csum += a[cur++]; } go[i].push_back({(ll) cur, sum * j - csum * n, a[cur] * n}); } go[i].push_back({(ll) l, 0ll, 1ll}); } vector<Val> ans; vector<int> p; vector<bool> used(n, false); for (int i = 0; i < n; ++i) { int nxt = -1; for (int j = 0; j < n; ++j) { if (used[j]) continue; if (nxt == -1 || cmp(go[j][i], go[nxt][i])) { nxt = j; } } used[nxt] = true; ans.push_back(go[nxt][i]); p.push_back(nxt); } ans.pop_back(); for (auto v : ans) { cout << v[0] * v[2] + v[1] << " " << v[2] << "\n"; } for (int v : p) { cout << v + 1 << " "; } }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...