#K51127. Calorie Intake Optimization
Calorie Intake Optimization
Calorie Intake Optimization
You are given the number of days D and a daily calorie target T. For each day, a list of calorie counts for various dishes is provided. Your task is to determine which day (using 1-indexing) has a total calorie intake that is as close as possible to T without exceeding it.
More formally, let \( S_i = \sum_{j=1}^{n_i} d_{ij} \) be the total calorie intake on day \( i \). You need to find the day \( k \) such that:
[ \begin{aligned} & S_k \leq T \quad \text{and} \[6pt] & S_k = \max { S_i \mid S_i \leq T } \end{aligned} ]
If no day satisfies the condition, output -1.
inputFormat
The input is read from stdin
and is formatted as follows:
- The first line contains two integers D and T, where 1 ≤ D ≤ 1000 and T is the calorie target.
- Each of the next D lines starts with an integer N indicating the number of dishes for that day, followed by N integers representing the calorie counts of the dishes.
outputFormat
Output a single integer to stdout
representing the 1-indexed day number with the total calorie intake closest to T without exceeding it. If no day meets the requirement, output -1.
3 1500
3 800 600 300
2 1000 400
4 200 300 700 500
2