Team Formation
Time limit6sMemory limit1024 MB
For each query, find the largest (A1[i]+A2[j]) times (B1[i]+B2[j]) over a range of boys i and a range of girls j.
- Level
Hard8 of 10
- Topics
- Geometry, Segment tree, Divide and conquer, Sorting
- Solved
- No attempts yet
Problem
In the 20XX International Informatics Olympiad, a mixed category was added. In this category, one boy and one girl form a team to solve problems. The olympiad committee selected boy candidates and girl candidates to form the national teams for the mixed category. The boy candidates are numbered from to , and the girl candidates are numbered from to .
A team's strength depends on both the ideation ability and the implementation ability of the two students on the team. Each ideation ability and implementation ability is an integer from to . The ideation ability of boy is , and his implementation ability is . The ideation ability of girl is , and her implementation ability is . If boy and girl form a team, the strength of that team is .
Every candidate was selected after fierce competition, so no boy is better than another boy in both ideation and implementation. More precisely, the ideation ability of the boys increases as the number grows, and the implementation ability decreases as the number grows. That is, and hold for every . The girls follow the same rule: and hold for every .
The committee wants to form a team with the maximum strength under several scenarios. There are scenarios, numbered from to . In scenario , the boy's number must be at least and at most , and the girl's number must be at least and at most . Write a program that finds, for each scenario, the maximum strength of a team that can be formed under these conditions.
Constraints
- For all ,
- For all ,
- For all , and
- For all , and
- For all ,
- For all ,