직선 위 소들이 만날 때 속도를 교환하며 이동한다. 멈춘 소들의 무게 합이 전체의 절반이 되는 시점까지 일어난 만남의 수를 구한다.
어려움8시뮬레이션정렬누적 합이분 탐색아직 제출이 없습니다시간 제한1초메모리 제한512 MBTwo barns are located at positions 0 and L (1≤L≤109) on a one-dimensional number line. There are also N cows (1≤N≤5⋅104) at distinct locations on this number line (think of the barns and cows effectively as points). Each cow i is initially located at some position x_i and moving in a positive or negative direction at a speed of one unit per second, represented by an integer d_i that is either 1 or −1. Each cow also has a weight w_i in the range \[1,103]. All cows always move at a constant velocity until one of the following events occur:
Let T 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 0…T (including at time T).
The first line contains two space-separated integers N and L.
The next N lines each contain three space-separated integers w_i, x_i, and d_i. All locations x_i are distinct and satisfy 0\<x_i\<L.
Print a single line containing the answer.
The cows in this example move as follows:
Exactly two meetings occurred.