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 maxn 2005
#define pll pair<ll, ll>
#define ff first
#define ss second
#define io ios_base::sync_with_stdio(0);cin.tie(0);
const ll inf = 1<<30;
ll a[maxn][maxn];
pll b[maxn][maxn];
bool vis[maxn];
int main() {
io
int n, l;
cin >> n >> l;
for (int i = 0;i < n;i++) {
ll tot = 0;
for (int j = 0;j < l;j++) {
cin >> a[i][j];
tot += a[i][j];
a[i][j] *= n;
}
ll cur = 0, ind = 0;
for (int j = 1;j <= n;j++) {
while (ind < l && cur + a[i][ind] <= tot*j) {
cur += a[i][ind];
ind++;
}
if (ind == l) b[i][j] = {l, 1};
else b[i][j] = {(tot * j - cur) + ind*a[i][ind], a[i][ind]};
}
}
auto cmp = [&] (pll x, pll y){return x.ff * (y.ss/n) < (x.ss/n) * y.ff;};
vector<int> ans;
vector<pll> frac;
for (int i = 1;i <= n;i++) {
pll best = {inf, 1};
int bind = 0;
for (int j = 0;j < n;j++) {
if (!vis[j] && !cmp(best, b[j][i])) {
best = b[j][i];
bind = j;
}
}
ans.push_back(bind+1);
vis[bind] = 1;
frac.push_back(best);
}
frac.pop_back();
for (auto i:frac) cout << i.ff << " " << i.ss << "\n";
for (int i:ans) cout << i << " ";
cout << endl;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |