시간 제한 메모리 제한 제출 정답 맞은 사람 정답 비율
1 초 1024 MB 6 6 5 100.000%

문제

It’s lunchtime at your school! Your N friends are all standing on a long field, as they usually do. The field can be represented as a number line, with the ith friend initially at position Pi metres along it. The ith friend is able to walk in either direction along the field at a rate of one metre per Wi seconds, and their hearing is good enough to be able to hear music up to and including Di metres away from their position. Multiple students may occupy the same positions on the field, both initially and after walking.

You’re going to hold a little concert at some position c metres along the field (where c is any integer of your choice), and text all of your friends about it. Once you do, each of them will walk along the field for the minimum amount of time such that they end up being able to hear your concert (in other words, such that each friend i ends up within Di units of c).

You’d like to choose c such that you minimize the sum of all N of your friends’ walking times. What is this minimum sum (in seconds)? Please note that the result might not fit within a 32-bit integer.

입력

The first line of input contains N.

The next N lines contain three space-separated integers, Pi, Wi, and Di (1 ≤ i ≤ N).

The following table shows how the available 15 marks are distributed.

출력

Output one integer which is the minimum possible sum of walking times (in seconds) for all N of your friends to be able to hear your concert.

제한

  • 1 ≤ N ≤ 200 000
  • 0 ≤ Pi ≤ 1 000 000 000
  • 1 ≤ Wi ≤ 1000
  • 0 ≤ Di ≤ 1 000 000 000

예제 입력 1

1
0 1000 0

예제 출력 1

0

If you choose c = 0, your single friend won’t need to walk at all to hear it.

예제 입력 2

2
10 4 3
20 4 2

예제 출력 2

20

One possible optimal choice of c is 14, which would require your first friend to walk to position 11 (taking 4 × 1 = 4 seconds) and your second friend to walk to position 16 (taking 4 × 4 = 16 seconds), for a total of 20 seconds.

예제 입력 3

3
6 8 3
1 4 1
14 5 2

예제 출력 3

43