문제
Two barns are located at positions and on a one-dimensional number line. There are also cows at distinct locations on this number line (think of the barns and cows effectively as points). Each cow is initially located at some position and moving in a positive or negative direction at a speed of one unit per second, represented by an integer that is either or . Each cow also has a weight in the range . All cows always move at a constant velocity until one of the following events occur: If cow reaches a barn, then cow stops moving.A meeting occurs when two cows and occupy the same point, where that point is not a barn. In this case, cow is assigned cow 's previous velocity and vice versa. Note that cows could potentially meet at points that are not integers.
Let be the earliest point in time when the sum of the weights of the cows that have stopped moving (due to reaching one of the barns) is at least half of the sum of the weights of all cows. Please determine the total number of meetings between pairs of cows during the range of time (including at time ).
SCORING:
Test cases 2-4 satisfy and for all Test cases 5-7 satisfy
입력
The first line contains two space-separated integers and .
The next lines each contain three space-separated integers , , and All locations are distinct and satisfy
출력
Print a single line containing the answer.
예제 입력 1
3 5
1 1 1
2 2 -1
3 3 -1
예제 출력 1
2
코드를 제출하려면 로그인이 필요합니다.
로그인