eolymp
bolt
Try our new interface for solving problems
Problems

Football club

Football club

Modern football clubs have a lot of players in their staff, but only \textbf{11} players can participate in a starting lineup in a particular match. One of them (goalkeeper) take the place near own team goal and is permitted to touch the ball with hands or arms within own penalty area. Other players have also some jobs and positions in the field. Defenders are mainly located on own side of the field, their job is to stop opposing attacking players from scoring. Midfielders are acted in the middle of field, helping to defenders or forwards, depending on game situation. And finally, forwards are located primarily on opposite side of the field and are responsible for scoring goals. Indeed each player can play at any position, but his efficiency at one position will be greater than at other position. This particularly depends on the experience of playing at corresponding position, individual skills and other factors. The number of players at each position, except goalkeeper, can vary, but must be conformed to one of allowed formations. You are a manager of the football club called ACM ILAN. There are \textbf{N} players in the club. For each player, his efficiency at each position is known. There are also \textbf{K} formations. You can choose and distribute players with respect to one of these formations. Write the program determining most suitable formation and starting lineup providing maximal total efficiency. \InputFile The first line of the input file contains two integers \textbf{N} and \textbf{K} (\textbf{11} ≤ \textbf{N} ≤ \textbf{30000}, \textbf{1} ≤ \textbf{K} ≤ \textbf{10}). Each of following \textbf{N} lines consists of \textbf{4} integers -- player efficiencies at position of goalkeeper, defender, midfielder and forward respectively. Efficiency is an integer between \textbf{0} and \textbf{100} inclusively. Each of last \textbf{K} lines contains \textbf{3} integers, determining allowed formation -- the number of defenders, midfielders and forwards in starting lineup when choosing this formation (the sum of these numbers is equal \textbf{10}). \OutputFile Output one number, the maximal total efficiency of starting lineup.
Time limit 2 seconds
Memory limit 64 MiB
Input example #1
12 3
90 10 10 10
20 50 40 30
20 90 20 70
30 60 20 60
30 70 20 20
20 80 50 70
80 20 20 20
10 20 40 80
20 30 80 30
10 20 90 60
10 40 40 90
10 50 20 80
4 4 2
4 3 3
3 4 3
Output example #1
850
Source International Collegiate Programming Contest, Ukraine, Quarter-Final,May 19, 2011