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

6921번 - Bridge Crossing 다국어

시간 제한메모리 제한제출정답맞힌 사람정답 비율
1 초 128 MB17131173.333%

문제

A rope bridge traverses a deep gorge. People may cross the bridge in groups, but there is a limit ($M$) to the size of the group. The time taken for a group to cross is determined by the slowest member. You are responsible for safety on the bridge and part of your job is to control the groups crossing. People are waiting in a queue (line), when the previous group has crossed you tell the next few people they can now cross. Groups can be of different sizes; no group can contain more than $M$ people, and the goal is to get everyone over in the shortest time, all the time maintaining the order of the people in the queue.

입력

The first line of the input contains an integer $M$ $(1 \le M \le 20)$. The second line contains $Q$ $(1 \le Q \le 100),ドル the length of the queue waiting to cross. For each person in the queue, a pair of input lines follows. The first of these is the name of the person, and the second is that person's individual time to cross the bridge. Recall that a group crossing time will be the maximum crossing time for time for any individual in the group.

출력

The first line of the output is to give the total crossing time for the entire queue of people. Then, output the names of the people in each group, one group per line, which will obtain the minimum overall crossing time. If several groupings yield the same overall crossing time, any such grouping may be listed.

제한

예제 입력 1

2
5
alice
1
bob
5
charlie
5
dobson
3
eric
3

예제 출력 1

Total Time: 9
alice
bob charlie
dobson eric

힌트

출처

Olympiad > Canadian Computing Competition & Olympiad > 2002 > CCC 2002 Senior Division 4번

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

출처

대학교 대회

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

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