CreateGroups
SRM 430 · 2008-12-20 · by Janq
Problem Statement
Constraints
- groups will contain between 1 and 50 elements, inclusive.
- Each element of groups will be between 1 and 1,000,000, inclusive.
- maxSize will be between 1 and 1,000,000, inclusive.
- minSize will be between 1 and maxSize, inclusive.
{10,20}
10
15
Returns: 5
We can move 5 students from the second time schedule to the first. Both schedules will then have a size of 15, which is the maximum allowed size.
{20,8,6}
10
15
Returns: 6
We can move 2 students from the first schedule to the second, and another 4 students from the first schedule to the third. The sizes of the resulting schedules will be 14, 10 and 10.
{10,20,30}
1
18
Returns: -1
There is no solution possible here. We have 60 students in 3 time schedules, so it is impossible to have at most 18 students per schedule.
{50,10,20,20,5}
15
30
Returns: 20
{100,200,301}
200
200
Returns: -1
Submissions are judged against all 95 archived test cases, of which 5 are shown here. Case numbers match the judge’s.
Language: C++17 · define a public class CreateGroups with a public method int minChanges(vector<int> groups, int minSize, int maxSize) · 95 test cases · 2 s / 256 MB per case