P4877 [USACO14FEB] Cow Decathlon G

Description

Farmer John's $N$ cows $(1

Input Format

* Line 1: Two space-separated integers: $N, B$ * Lines 2..B+1: Line i+1 will contain the information for bonus i which is three space- separated integers: $K_i, P_i, A_i$. * Lines B+2..B+N+1: Line B+1+j will contain the information on how cow j will perform at each of her events. This will be given in $N$ space-separated integers: $s_j1...s_jN.$

Output Format

* Line 1: The maximum amount of points that the cows can receive, including bonuses.

Explanation/Hint

Cow 1 will perform event 1, cow 3 will perform event 2, and cow 2 will perform event 3.