#P2965. [USACO09NOV] The Grand Farm-off S
[USACO09NOV] The Grand Farm-off S
Description
Farmer John owns cows (with ), numbered . Each cow has an integer weight and a utility rating .
He may enter a group of cows into the Grand Farm-off. He wants to choose cows whose total utility is maximized. If multiple sets of cows achieve the same maximum total utility, he prefers the set with the minimum possible total weight.
Among all selections of cows that maximize the total utility, find the minimum possible total weight, and output the remainder when this total weight is divided by (with ).
To speed up input, the weights and utilities are generated by polynomials. For each cow ,
Note that these formulae can generate duplicate values; your algorithm should handle this properly. Also, and .
Input Format
Line 1: Ten space-separated integers , , , , , , , , , .
Output Format
Line 1: A single integer — the remainder when the minimum possible total weight (among all selections of cows that maximize total utility) is divided by .
2 0 1 5 55555555 0 1 0 55555555 55555555
51
Hint
The functions generate weights of 5, 6, 9, 14, 21, and 30 along with utilities of 0, 1, 8, 27, 64, and 125.
The two cows with the highest utility are cows 5 and 6, and their combined weight is .
Translated by ChatGPT 5
京公网安备 11011102002149号