시간 제한메모리 제한제출정답맞힌 사람정답 비율
1 초 512 MB0000.000%

문제

Welcome to your new job at Paris Sightseeing for Groups (PSG). Just like every other employee at PSG, you are in charge of planning trips for groups of people. Your salary will be indexed on your “customer score”. This “customer score” is computed as the maximal h such that there are at least h groups that gave your trip a grade of at least h.

You have prepared several trips for each group according to their specific taste. You know in advance how each group will like each of your trips. However some of these possibilities will take more of your time and some will cost more than others. Since you cannot work 100 hours per week and you have a limited budget, you cannot simply maximize your “customer score” by taking the most liked trip for each group.

You want a program that tells you the maximal customer score that is possible to achieve considering your time and money budgets. Note that you have to plan exactly one trip for each group!

입력

The input comprises several lines, each consisting of integers separated with single spaces.

  • The first line contains three integers:
    • N the number of groups;
    • Mtot the total money that you have;
    • Ttot the total time dedicated for visits.
  • Then each of the N groups is described by several lines:
    • The first line contains the integer Pi which is the number of possibilities for the i-th group.
    • This line is followed by Pi lines, each containing three integers Mi,j, Ti,j, and Si,j describing the j-th possibility to the i-th group: Mi,j is the amount of money needed, Ti,j is the time for the visit, Si,j is the grade.

출력

The output should consist of a single line, whose content is an integer h, the maximal h such that it is possible to give a grade of at least h to at least h groups. If it is not possible to plan a trip for each group then the output should be −1.

제한

  • 0 ≤ Mi,j ≤ Mtot ≤ 2 500;
  • 0 ≤ Ti,j ≤ Ttot ≤ 2 500;
  • 0 ≤ Si,j ≤ 2 500;
  • 1 ≤ Pi ≤ 5;
  • 3 ≤ N ≤ 100.

예제 입력 1

3 3 3
1
1 1 1
2
2 0 1
0 3 2
2
3 0 2
0 2 1

예제 출력 1

1

There is only one assignment possible. We select the first possibility for the groups 1 and 2, and the second possibility for the third group. This amounts to 3 units of time and 3 units of money.

예제 입력 2

5 5 5
2
0 1 2
4 4 3
2
0 1 3
1 0 2
2
1 0 2
0 1 3
2
1 1 3
0 1 2
2
0 1 2
1 1 3

예제 출력 2

3

If we select the first possibility for the first group, then we can take the most liked possibility for all other groups. We can therefore serve all groups and ensure that 4 groups have a grade of 3.