package main import . "fmt" import "sort" type Unit struct { Id, Width, Height int } func main() { var n, k int Scan(&n, &k) tops := make([]*Unit, n) bodies := make([]*Unit, n*2) bottoms := make([]*Unit, n) for i := range tops { u := new(Unit) u.Id = i+1 Scan(&u.Width) tops[i] = u } for _, u := range tops { Scan(&u.Height) } for i := range bodies { u := new(Unit) u.Id = i+1 Scan(&u.Width) tops[i] = u } for _, u := range bodies { Scan(&u.Height) } for i := range bottoms { u := new(Unit) u.Id = i+1 Scan(&u.Width) tops[i] = u } for _, u := range bottoms { Scan(&u.Height) } sort.Slice(tops, func(i, j int) bool { return tops[i].Width < tops[j].Width }) sort.Slice(bodies, func(i, j int) bool { return bodies[i].Width < bodies[j].Width }) sort.Slice(bottoms, func(i, j int) bool { return bottoms[i].Width < bottoms[j].Width }) tops = tops[:k] bottoms = bottoms[len(bottoms)-k:] for i, top := range tops { btm := bottoms[i] body := []*Unit{} for len(bodies) > 0 && len(body) < 2 { tmp := bodies[0] if top.Width < tmp.Width && tmp.Width < btm.Width { body = append(body, tmp) } bodies = bodies[1:] } Println([]any{top.Id, body[0].Id, body[1].Id, btm.Id}...) } }