#P8101. [USACO22JAN] Multiple Choice Test P
[USACO22JAN] Multiple Choice Test P
Problem Description
The cows are taking a multiple-choice test. In a normal test, your choices for each question are graded separately and then added up, but in this test, your choices are added together first and then graded.
Specifically, you are given () groups of integer vectors on the 2D plane, where each vector is represented by an ordered pair . Choose one vector from each group so that the sum of the chosen vectors is as far from the origin as possible.
The input guarantees that the total number of vectors does not exceed . Each group contains at least vectors, and all vectors within the same group are distinct. The input also guarantees that the absolute value of each and coordinate does not exceed .
Input Format
The first line contains , the number of groups of vectors.
For each group, the first line contains , the number of vectors in the group. The next lines contain the vectors in the group. Adjacent groups are separated by a blank line.
Output Format
Output the maximum possible squared Euclidean distance.
3
2
-2 0
1 0
2
0 -2
0 1
3
-5 -5
5 1
10 10
242
Hint
[Sample Explanation]
The best plan is to choose from the first group, from the second group, and from the third group. The sum of these vectors is , and its squared distance from the origin is .
[Constraints]
- In test cases 1-5, the total number of vectors does not exceed .
- In test cases 6-9, each group contains exactly vectors.
- In test cases 10-17, there are no additional restrictions.
Problem provided by: Benjamin Qi.
Translated by ChatGPT 5