#454
Unrated
Meetings
시간 제한
2s
메모리 제한
1024MB
제출
0
정답
0
맞힌 사람
0
정답 비율
0.0%

문제

Two barns are located at positions 00 and LL (1L109)(1\le L\le 10^9) on a one-dimensional number line. There are also NN cows (1N5104)(1\le N\le 5\cdot 10^4) at distinct locations on this number line (think of the barns and cows effectively as points). Each cow ii is initially located at some position xix_i and moving in a positive or negative direction at a speed of one unit per second, represented by an integer did_i that is either 11 or 1-1. Each cow also has a weight wiw_i in the range [1,103][1,10^3]. All cows always move at a constant velocity until one of the following events occur: If cow ii reaches a barn, then cow ii stops moving.A meeting occurs when two cows ii and jj occupy the same point, where that point is not a barn. In this case, cow ii is assigned cow jj's previous velocity and vice versa. Note that cows could potentially meet at points that are not integers.

Let TT 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 0T0 \ldots T (including at time TT).

SCORING:

Test cases 2-4 satisfy N102N\le 10^2 and wi=1w_i=1 for all i.i. Test cases 5-7 satisfy N102.N\le 10^2.

입력

The first line contains two space-separated integers NN and LL.

The next NN lines each contain three space-separated integers wiw_i, xix_i, and di.d_i. All locations xix_i are distinct and satisfy 0<xi<L.0<x_i<L.

출력

Print a single line containing the answer.

예제 입력 1

3 5
1 1 1
2 2 -1
3 3 -1

예제 출력 1

2
코드 제출

코드를 제출하려면 로그인이 필요합니다.

로그인
내 제출
제출 내역이 없습니다.
맞은 사람
아직 맞은 사람이 없습니다.
난이도 투표
Unrated0명 투표
로그인 후 AC 받으면 투표할 수 있습니다.
전체 제출
제출 내역이 없습니다.