#include using namespace std; using pii=pair; using tii=tuple; using qii=tuple; using ll=long long; using ld=long double; const int INF=1e9; #define rep(i,n) for (int i=0;i<(int)(n);i++) #define all(v) v.begin(),v.end() template void chmin(T &a,T b){ if(a>b){ a=b; } } template void chmax(T &a,T b){ if(a> tree; //0->back,1->front->2->center struct Solver{ double score(vector> &ans){ ll sum_h2=0; int sum_h=0; rep(i,K){ int now=0; rep(j,4){ now+=tree[min(2,j)][ans[i][j]].h; } sum_h2+=(ll)now*(ll)now; sum_h+=now; } return ((double)sum_h2/(double)K)-((double)sum_h/(double)K)*((double)sum_h/(double)K); } int true_score(vector> &ans){ int mx=-INF,mn=INF; rep(i,K){ int now=0; rep(j,4){ now+=tree[min(2,j)][ans[i][j]].h; } chmax(mx,now); chmin(mn,now); } return mx-mn; } void solve(){ set st_back,st_center; rep(i,N) st_back.insert({tree[0][i].w,i}); rep(i,2*N) st_center.insert({tree[2][i].w,i}); vector> ans(K,vector(4,-10)); //back->front->center1->center2 int cnt_tree=0; vector front_ord(N),center_ord(2*N); rep(i,N) front_ord[i]=i; rep(i,2*N) center_ord[i]=i; sort(all(front_ord),[&](int i,int j){return tree[1][i].w>tree[1][j].w;}); sort(all(center_ord),[&](int i,int j){return tree[2][i].w> used(3,vector(2*N,0)); rep(i,K){ rep(j,4){ used[min(2,j)][ans[i][j]]=1; } } vector> not_used(3); rep(i,3){ rep(j,2*N){ if(i!=2&&j==N) break; if(!used[i][j]) not_used[i].push_back(j); } } mt19937 mt; double min_score=true_score(ans); auto start=chrono::system_clock::now(); while(true){ auto now=chrono::system_clock::now(); int ms=chrono::duration_cast(now-start).count(); if(1200<=ms) break; vector> new_ans=ans; int x=mt()%K,y=mt()%4; int z=mt()%not_used[min(2,y)].size(); swap(new_ans[x][y],not_used[min(2,y)][z]); bool ok=true; rep(i,3){ if(new_ans[x][i+1]<=new_ans[x][i]){ ok=false; break; } } if(!ok) continue; double new_score=true_score(new_ans); if(new_score<=min_score){ min_score=new_score; ans=new_ans; } } rep(i,K){ cout << ans[i][1]+1 << ' ' << ans[i][2]+1 << ' ' << ans[i][3]+1 << ' ' << ans[i][0]+1 << '\n'; } } }Solver; int main(){ ios::sync_with_stdio(false); cin.tie(nullptr); cin >> N >> K; tree.resize(3); tree[1].resize(N); tree[2].resize(2*N); tree[0].resize(N); rep(i,N) cin >> tree[1][i].w; rep(i,N) cin >> tree[1][i].h; rep(i,2*N) cin >> tree[2][i].w; rep(i,2*N) cin >> tree[2][i].h; rep(i,N) cin >> tree[0][i].w; rep(i,N) cin >> tree[0][i].h; Solver.solve(); }