제출 #535008

#제출 시각아이디문제언어결과실행 시간메모리
535008malokovNaan (JOI19_naan)C++17
100 / 100
463 ms116508 KiB
#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 timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...