当前你的浏览器版本过低,网站已在兼容模式下运行,兼容模式仅提供最小功能支持,网站样式可能显示不正常。
请尽快升级浏览器以体验网站在线编辑、在线运行等功能。
Jack and Joe are playing a special card game in which each card has some points in three properties apo, bqu and cri. Jack has one card while Joe has the other N - 1 cards. Every round Joe picks one of his cards and compares it with Jack's card. The one has the more powerful card wins the round. The rule is as follows:
After the compare, Joe's card is discarded so that he can never use it any more.
To make the game more competitive, Jack and Joe are given m chances each to enhance the cards. For each time, Jack may add 1 point to either property of his card while Joe may add 1 point to bqu of one card and 1 point to cri of another.
Joe wants to know how many rounds he can win if they both plays optimally.
Input consists several test case.
The first line of each test case is N (N ≤ 100000), the total number of cards.
The following N lines describe the cards. Each line contains three integers a, b, c (a, b, c ≤ 10000) which present the number of points in apo, bqu and cri of that card respectively. Jack has the first card.
The last of each test case is M (M ≤ 10000000), the number of chances to enhance cards.
The input ends with N = 0.
For each test case, output how many rounds Joe can win.
3 0 0 0 1 0 0 1 0 0 1 3 0 0 0 0 0 0 0 0 0 0 0
2 0
时间上限 | 内存上限 |
1000 | 65536 |