#pragma GCC optimize("O3")
#include<bits/stdc++.h>
#define int int_fast64_t
using namespace std;
typedef pair<int,int> pii;
#define REP(i,j,k) for(register int i=(j);i<(k);++i)
#define f first
#define s second
#define endl '\n'
#define IOS cin.tie(0),cout.tie(0),ios_base::sync_with_stdio(false)
const int maxn=2009;
int n,l,p[maxn],v[maxn][maxn];
bitset<maxn>us;
main(){
IOS;
cin>>n>>l;
REP(i,0,n){
v[i][0]=0;
REP(j,0,l)cin>>v[i][j+1],v[i][j+1]+=v[i][j];
}
pii cur={0,1};
REP(i,1,n){
int opt=-1;
pii ls={1,0};
REP(j,0,n){
if(us[j])continue;
int k=cur.f/cur.s;
pii t={v[j][k]*n*cur.s+(v[j][k+1]-v[j][k])*(cur.f%cur.s)*n+v[j][l]*cur.s,n*cur.s};
// assert(v[j][k]*n*cur.s<7e18);
while((__int128)v[j][k+1]*t.s<=t.f)++k;
int vv=v[j][k+1]-v[j][k];
t={k*vv*n+((__int128)t.f*n+t.s-1)/t.s-v[j][k]*n,vv*n};
assert(t.f<4e11);
assert(t.f>=0)
if((__int128)t.f*ls.s<(__int128)ls.f*t.s)opt=j,ls=t;
}
p[i]=opt;
us[opt]=1;
cur=ls;
cout<<ls.f<<" "<<ls.s<<endl;
}
REP(i,1,n)cout<<p[i]+1<<" ";
REP(i,0,n)if(!us[i])cout<<i+1<<endl;
}
Compilation message
naan.cpp:16:6: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
main(){
^
naan.cpp: In function 'int main()':
naan.cpp:37:4: error: expected ';' before 'if'
if((__int128)t.f*ls.s<(__int128)ls.f*t.s)opt=j,ls=t;
^~