A farming cooperative keeps its harvest records in a wide ledger: one line per plot, with a fixed set of crop columns holding that plot's harvest weight (in kilograms) for each crop. The cooperative is switching its inventory system to a format that expects one record per plot-crop pair instead of one wide row per plot. Write a program that expands the wide ledger into this per-pair record format.
n and k, separated by a space — the number of plots and the number of crop columns.k crop names, space-separated. Each crop name is a non-empty string of lowercase letters and digits (at most 20 characters); all crop names are distinct.n lines each describe one plot: a plot identifier (a non-empty string of lowercase letters and digits, at most 20 characters, distinct across all plots), followed by k integers giving that plot's harvest weight for each crop, in the same left-to-right order as the crop names on line 2.Print exactly n * k lines. Process the plots in the order they appear in the input, and for each plot process its crops in the order the crop names appear in the header. For every (plot, crop) pair, print one line: <plot_id> <crop_name> <weight>, with a single space between the three fields.
Example 1
Input
2 3 wheat corn rice p1 10 20 30 p2 5 0 15
Expected
p1 wheat 10 p1 corn 20 p1 rice 30 p2 wheat 5 p2 corn 0 p2 rice 15
Explanation
There are 2 plots and 3 crops (wheat, corn, rice). For plot p1 the weights in header order are 10, 20, 30, so the pair records are `p1 wheat 10`, `p1 corn 20`, `p1 rice 30`. Plot p2 follows with weights 5, 0, 15, giving `p2 wheat 5`, `p2 corn 0`, `p2 rice 15`. The output lists p1's three pairs before p2's three pairs, for 6 lines total.
Example 2
Input
1 2 soy oat plot1 -3 7
Expected
plot1 soy -3 plot1 oat 7
Explanation
There is one plot, plot1, with two crops soy and oat and weights -3 and 7. The output has two lines, one per crop in header order: `plot1 soy -3` (a negative weight represents an already-applied correction) and `plot1 oat 7`.
Ready to solve this?
Sign in to open the editor, run your code against the sample tests, and submit against the full test suite.
Sign in to solve →