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) bodies[i] = u } for _, u := range bodies { Scan(&u.Height) } for i := range bottoms { u := new(Unit) u.Id = i+1 Scan(&u.Width) bottoms[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 }) for _, btm := range bottoms[:k] { var top *Unit for len(tops) > 0 && top == nil { if tops[0].Width > btm.Width { top = tops[0] } tops = tops[1:] } body := make([]*Unit, 0, 2) for len(bodies) > 0 && len(body) < 2 { tmp := bodies[0] if top.Width < tmp.Width { body = append(body, tmp) } bodies = bodies[1:] } Println([]any{top.Id, body[0].Id, body[1].Id, btm.Id}...) } }