RiseOJ는 solved.ac와 제휴 관계가 없습니다. 티어 아이콘 © solved.ac. solved.ac
포럼
COCI00065

Barica

스페셜 저지 — 출력을 사용자 정의 프로그램으로 검사하므로 여러 정답이 인정될 수 있습니다.
Platinum III 플래티넘 III
난이도
2s
시간 제한
32MB
메모리 제한
1
맞았습니다!!
1
제출 수
100.0%
정답률
레이팅

의견: 0

설명

Barica is an unusual frog. She lives in a pond where \(N\) plants float on the surface of the water. The plants are numbered \(1\) through \(N\). When viewing from above, the location of each plant is given by a pair of coordinates. What makes Barica unusual is her fear of jumping diagonally and in the negative direction. More precisely, she can jump from a plant at coordinates \((x_1, y_1)\) to another at coordinates \((x_2, y_2)\) only if:

  • \(x_2 > x_1\) and \(y_2 = y_1\), or
  • \(y_2 > y_1\) and \(x_2 = x_1\)

For each plant, we know the number of flies in its immediate vicinity. Barica can use her swift tongue to eat all flies near the plant she is at.

Barica absorbs one energy unit for each fly she eats, and uses \(K\) energy units for each jump she makes. Barica can not make a jump if she doesn't have enough energy units beforehand.

Barica wants to go from plant \(1\) to plant \(N\) and have the largest amount of energy possible after arriving. Barica initially has no energy and must gather energy for her first jump from the flies around plant \(1\).

Find the sequence of plants Barica should travel to achieve her goal.

제약
입력 형식

The first line of input contains two integers \(N\) and \(K\) (\(2 \le N \le 300\,000\), \(1 \le K \le 1000\)) separated by a space.

Each of the following \(N\) lines contains three integers \(X\), \(Y\) and \(F\) (\(0 \le X, Y \le 100\,000\), \(0 \le F \le 1000\)) separated by spaces, meaning that there is a plant at coordinates \((X, Y)\) with \(F\) flies around it. The first plant in the input is plant \(1\), the second is plant \(2\) etc.

No two plants will share the same pair of coordinates.

Note: The input data will guarantee that a sequence of jumps, although not necessarily unique, will always exist.

출력 형식

Output the final energy level on the first line.

Output an integer \(L\), the number of plants Barica should travel, including plants \(1\) and \(N\).

On the following \(L\) lines, output the coordinates of the plants Barica should travel, in order.

서브태스크
서브태스크점수설명

Subtask 1

70점
예제 1
입력
6 5
1 1 5
2 1 5
1 2 4
2 3 5
3 2 30
3 3 5
출력
5
4
1 1
2 1
2 3
3 3
예제 2
입력
8 10
1 1 15
2 2 30
1 2 8
2 1 7
3 2 8
2 3 7
4 2 100
3 3 15
출력
36
5
1 1
1 2
2 2
3 2
3 3
예제 3
입력
9 5
5 5 10
6 5 2
7 5 1
5 6 2
6 6 6
7 6 2
5 7 1
6 7 2
7 7 1
출력
2
3
5 5
7 5
7 7
문제 정보

riseoj 작성

출처 COCI 2007/2008 Contest 5

평가 및 의견

Barica

개요
출제자 난이도 Platinum III 플래티넘 III 의견 0 / 50 공개 집계 (커뮤니티 난이도, 주요 주제, 품질)는 의견이 충분히 모이면 공개됩니다.

Log in to rate problems.

개별 의견

아직 의견이 없습니다. 자격이 된다면 위 양식에서 가장 먼저 평가해 보세요.

풀이 제출

Barica

게스트로 둘러보고 있습니다. 로그인하면 풀이를 제출하고 진행 상황을 확인할 수 있습니다. 로그인하고 제출하기
공개
C++20 Tab 들여쓰기 · Ctrl+/ 주석 토글 · Enter 자동 들여쓰기
1 1 1 0 공백: 4 · UTF-8