Logo
(追記) (追記ここまで)

13381번 - Jump 다국어

시간 제한메모리 제한제출정답맞힌 사람정답 비율
2 초 512 MB61121055.556%

문제

In ACM city, there are N tiles staying in two-dimensional Cartesian coordinate (xi, yi). Each tile has a power bottle for boosting the jumping energy ei.

You can jump only right or up direction. That is, you can jump from a tile (x1, y1) to a tile (x2, y2) only if y1=y2 and x1<x2 (right direction) or x1=x2 and y1<y2 (up direction).

Each time you jump, you have to loss your jumping energy B. You could not jump if your jumping energy is less than B and when you reach the new tile, you will get the power bottle for boosting your jumping energy ei immediately.

You initially stay in the first tile and you initially have energy e1. Your mission is to jump from the first-tile to the N-th tile (the last tile) and also get the maximum energy. In this task, you can jump only from a tile to a tile. You cannot jump outside the tile.

Your task

Write a program to find the maximum energy to jump from the first tile to the N-th tile.

입력

The first line of the input contains an integer T, the number of test cases (1 <= T <= 10). Then T test cases follow in the format described below.

The first line of each test case contains two positive integers N and B. (2 <= N <= 300,000; 1 <= B <= 1,000)

The next N lines describe each tile from the first tile to the N-th tile. Each line contains three integers xi yi ei (0 <= xi, yi <= 100,000; 0 <= ei <= 1,000)

Guarantee that no two tiles stay in the same coordinate and there is a way that you can jump from the first tile to the N-th tile.

출력

The output contains T lines show the maximum energy to jump from the first tile to the N-th tile.

제한

예제 입력 1

2
6 20
10 10 20
15 10 20
10 15 15
15 20 20
20 15 200
20 20 20
6 20
10 10 20
15 10 20
10 15 20
15 20 20
20 15 200
20 20 20

예제 출력 1

20
200

힌트

출처

ICPC > Regionals > Asia Pacific > Thailand > Asia Thailand National Programming Contest > 2015 ACM-ICPC Thailand National Programming Contest E번

(追記) (追記ここまで)

출처

대학교 대회

  • 사업자 등록 번호: 541-88-00682
  • 대표자명: 최백준
  • 주소: 서울시 서초구 서초대로74길 29 서초파라곤 412호
  • 전화번호: 02-521-0487 (이메일로 연락 주세요)
  • 이메일: contacts@startlink.io
  • 통신판매신고번호: 제 2017-서울서초-2193 호

AltStyle によって変換されたページ (->オリジナル) /