Cleaning Stations
InterviewTime limit2sMemory limit512 MB
Given weights and a feature matrix, print the indices of the rows whose weighted sum is largest, in ascending order, for each of K data sets.
- Level
Easy2 of 10
- Topics
- Implementation, Array, Math
- Solved
- No attempts yet
Problem
One of the symbiotic relationships among marine animals is the cleaning station. A cleaning station is a place such as a sea mount where cleaner fish gather in large numbers. A large fish such as a shark swims up to a cleaning station and picks out cleaner fish to take the parasites off its skin. The cleaner fish get a meal and the shark gets cleaned. Both profit.
A shark is defenseless while it is being cleaned, so it is very picky about which fish it lets near. If anything seems off, it leaves at once. The caution is earned. Some cleaner fish take small bites out of the shark along with the parasites.
A shark judges a cleaner fish by several features, and it assigns every feature a weight that is either positive or negative. One shark may prefer a larger cleaner fish, want a shorter distance to swim, and want the cleaner fish to move slowly. Given the feature values of every cleaner fish, find all the cleaner fish whose weighted sum of feature values is the largest.
Input
The first line contains the number of data sets. data sets follow, each in the format below.
The first line of a data set contains two integers and . is the number of cleaner fish, with , and is the number of features the shark judges by, with .
The next line contains integers , the weights the shark assigns to the features. Every weight is between and .
Then come lines, one per cleaner fish. The -th of those lines contains integers , the feature values of cleaner fish . Every is an integer between and .
Output
For each data set, first print Data Set x: on a line of its own, where is the number of the data set counting from .
Then print, in ascending order and one per line, the numbers of all cleaner fish whose weighted sum is the largest. Cleaner fish are numbered through in input order.
Print one blank line after the output of each data set.