문제
Two barns are located at positions
If cow
i reaches a barn, then cowi stops moving.A meeting occurs when two cows
i andj occupy the same point, where that point is not a barn. In this case, cowi is assigned cowj 's previous velocity and vice versa. Note that cows could potentially meet at points that are not integers.
Let
SCORING:
Test cases 2-4 satisfy
N\le 10^2 andw_i=1 for alli. Test cases 5-7 satisfy $N\le 10^2.$
Problem credits: Benjamin Qi
입력
The first line contains two space-separated integers
The next
출력
Print a single line containing the answer.
예제1
3 5
1 1 1
2 2 -1
3 3 -1
2
The cows in this example move as follows:
The first and second cows meet at position 1.5 at time 0.5. The first cow now has velocity
-1 and the second has velocity1. The second and third cows meet at position 2 at time 1. The second cow now has velocity
-1 and the third has velocity1. The first cow reaches the left barn at time 2.
The second cow reaches the left barn at time 3.
The process now terminates since the sum of the weights of the cows that have reached a barn is at least half of the sum of the weights of all cows. The third cow would have reached the right barn at time 4.
Exactly two meetings occurred.