Dungeon Difficulty
You are a game developer at Team Berry and you have released a wildly successful indie game called Solid Knight. It is so successful that people are skipping classes and even AUCPL competitions to play it! However, many players are complaining that certain sections of the game are too hard, so you want to tune the game balance by separating the game stages into two distinct chapters.
Each stage in the game has a different difficulty value, detailing how hard it is to complete. You want to split the given game stages into two contiguous chapters at some point such that the balance ratio of the chapters is as close to as possible. The balance ratio of a given split is defined as follows: given
game stages with elements
(1-indexed) and a split index
, the game balance is
We want to find such that
is minimised. If multiple
values would have the same best split, output the lowest one.
Input
The first line contains a single integer , the number of stages in the game.
The next line contains space-separated integers
, the difficulties of each stage.
Output
Output the -based index
of the position where we should split the game chapters in order to make the above defined balance ratio as close to
as possible. Note that the chapter one includes game
while chapter two doesn't. In the case of ties, i.e. multiple splits have the same minimal absolute difference, output the earlier index.
Example
Input 1
5
2 2 6 6 6
Output 1
4
We will enumerate all possibilities to find the optimal split:
: Average of chapter one is
, average of chapter two is
. The balance ratio is
.
: Average of chapter one is
, average of chapter two is
. The balance ratio is
.
: Average of chapter one is
, average of chapter two is
. The balance ratio is
.
: Average of chapter one is
, average of chapter two is
. The balance ratio is
.
Thus, the split at is optimal as
is closest to one. We can illustrate this by finding the absolute difference with one and then converting to a common denominator:
The final one is the lowest difference, hence why is the output.
Input 2
7
5 3 1 2 3 6 1
Output 2
3
We can perfectly split into two sections with equal averages.
Comments