#K69267. Best Dish Selection
Best Dish Selection
Best Dish Selection
Alex is curating a balanced menu for his restaurant. Given several dishes, each described by their cooking time, consistency, and taste, and a customer’s preferred values for these attributes, your task is to identify the dish that most closely matches the customer’s preferences.
The closeness is calculated as the sum of the absolute differences between each dish attribute and the corresponding customer preference. In other words, for a dish with attributes \( (c, d, t) \) and customer preferences \( (p, q, r) \), the closeness \( C \) is defined as:
\( C = |c - p| + |d - q| + |t - r| \)
If more than one dish has the same minimal closeness value, choose the dish with the smallest 1-based index.
inputFormat
The input is read from standard input (stdin). The first line contains an integer ( T ) denoting the number of test cases. For each test case:
- The first line contains an integer ( N ) indicating the number of dishes.
- The next ( N ) lines each contain three space-separated integers, representing the cooking time, consistency, and taste of a dish.
- The following line contains three space-separated integers representing the customer’s preferred cooking time, consistency, and taste.
outputFormat
For each test case, output a single line to standard output (stdout) containing the 1-based index of the dish that best matches the customer’s preferences.## sample
2
3
4 6 8
2 3 5
7 8 9
5 6 7
1
3 7 9
3 7 9
1
1
</p>