This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
// vaziat meshki-ghermeze !
#include <bits/stdc++.h>
#define pb push_back
#define F first
#define S second
#define all(x) x.begin(), x.end()
#define debug(x) cerr << #x << " : " << x << '\n'
using namespace std;
typedef long long ll;
typedef long double ld;
typedef string str;
typedef pair<ll, ll> pll;
const ll Mod = 1000000007LL;
const int N = 2e5 + 10;
const ll Inf = 2242545357980376863LL;
const ll Log = 30;
typedef pll frac;
bool CMP(frac A, frac B){
ll cA = A.F / A.S;
ll cB = B.F / B.S;
if(cA != cB)
return cA < cB;
return (A.F % A.S) * B.S < A.S * (B.F % B.S);
}
ll V[N];
vector<frac> cut[N];
int mk[N];
int main(){
ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
int n, L;
cin >> n >> L;
for(int p = 0; p < n; p++){
ll sm = 0;
for(int i = 0; i < L; i++){
cin >> V[i];
sm += V[i];
}
int po = 0;
ll smnw = 0;
for(int it = 1; it < n; it ++){
while(n * (V[po] + smnw) <= sm * it){
smnw += V[po];
po ++;
}
frac alp = frac(it * sm - smnw * n, n * V[po]);
frac bet = frac(alp.F + po * alp.S, alp.S);
cut[p].pb(bet);
}
// cerr << p << " : ";
// for(auto [up, dw] : cut[p]) cerr << up << "/" << dw << '\n';
// cerr << '\n';
}
vector<int> P;
for(int i = 0; i < n - 1; i++){
int idx = -1;
for(int j = 0; j < n; j++){
if(mk[j])continue;
if(idx == -1) idx = j;
if(CMP(cut[j][i], cut[idx][i]))
idx = j;
}
mk[idx] = 1;
cout << cut[idx][i].F << ' ' << cut[idx][i].S << '\n';
P.pb(idx + 1);
}
for(int i = 0; i < n; i++) if(!mk[i]) P.pb(i + 1);
for(auto x : P) cout << x << ' ';
cout << '\n';
return 0;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |