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;
using ll = long long;
bool operator < (const array<ll, 2> a, const array<ll, 2> b) {
return a[0]*b[1] < b[0]*a[1];
}
int n, m, c[2020][2020];
bool chk[2020];
array<ll, 2> p[2020][2020];
int main() {
cin.tie(0)->sync_with_stdio(0);
cin >> n >> m;
for(int i=1;i<=n;i++) for(int j=1;j<=m;j++) cin >> c[i][j];
for(int i=1;i<=n;i++) {
ll sum = 0;
for(int j=1;j<=m;j++) sum += c[i][j];
ll s = 0;
for(int j=1, k=0;j<n;j++) {
while(k < m && (s + c[i][k+1]) * n <= sum * j) s += c[i][++k];
ll C = c[i][k+1];
p[i][j] = {sum*j-s*n + k*C*n, C*n};
assert(j == 1 || p[i][j-1] < p[i][j]);
}
}
vector<int> ans;
for(int i=1;i<n;i++) {
int mn = 1;
while(chk[mn]) mn++;
for(int j=1;j<=n;j++) if(!chk[j] && p[j][i] < p[mn][i]) mn = j;
assert(1 <= p[mn][i][1] && p[mn][i][1] <= (int)1e9);
cout << p[mn][i][0] << " " << p[mn][i][1] << "\n";
chk[mn] = 1, ans.push_back(mn);
}
for(auto x : ans) cout << x << " ";
for(int i=1;i<=n;i++) if(!chk[i]) cout << i;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |