Field Trip
InterviewTime limit3sMemory limit1024 MB
Split class sections 1 to N into three contiguous groups so that no teacher rides a bus, printing the split points i and j or -1 if impossible.
- Level
Medium5 of 10
- Topics
- Prefix sum, Binary search
- Solved
- No attempts yet
Problem
You and your classmates are going on an exciting field trip to a downtown museum. Because the museum is an hour away, three buses of identical capacity and a van are dispatched to take everyone to the museum and back. The buses first load only students. Once all students are loaded, teachers fill the remaining spots on the buses. Any teachers left over ride on the van. All the students hope for a "teacher free bus ride," meaning none of the teachers are on a bus.
Students are grouped in class sections of different sizes. Each class section is assigned a number from to . All students in one class section must ride on the same bus. The buses board class sections in increasing order by number. The first bus loads sections to , the second bus loads sections to , and the third bus loads sections to . Every bus must have at least one class section assigned to it.
Given the sizes of the class sections, determine whether it is possible to load students onto the three identical buses and end up with a "teacher free bus ride."
Input
The first line of input contains one integer , the number of class sections (). The second line contains integers, where the th integer is the size of the class section with number . Class section sizes range from to .
Output
If it is possible to load the students onto the three buses in the described way with a teacher free bus ride, output two integers and (). Here is the number of the class section loaded last onto the first bus, and is the number of the class section loaded last onto the second bus. The third bus loads sections to .
If it is not possible, print "-1".