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

21193번 - Magic Scale 스페셜 저지다국어

시간 제한메모리 제한제출정답맞힌 사람정답 비율
3 초 512 MB228373045.455%

문제

A treasure is locked into a room of a well-guarded dungeon. At the door of the room, there is a magic scale and a set of N weights. The scale has an associated unknown target total weight W. We have the following properties:

  • It is guaranteed that a subset of the weights will sum to exactly W.
  • When the total weight on the scale is exactly W, the door opens, unlocking the treasure.
  • If the total weight on the scale is less than W, nothing happens.
  • As a security measure, if the total weight on the scale exceeds W, the door will be forever locked.

One way to guarantee opening the door and reaching the coveted treasure is therefore to try all subsets of the N weights in order of increasing total weight. However, multiple subsets might have the same total weight, so a better strategy is to try one subset for each given total weight.

Help our adventurer by enumerating the first K possible total weights in increasing order, together with one corresponding subset of weights for each total weight.

입력

  • The first line contains a single integer N.
  • The second line contains a single integer K.
  • The third line contains a space-separated list of N integers representing the N weights.

출력

K lines representing the first K possible total weights in increasing order, together with the corresponding weights. The format of each of the K lines is:

total_weight: weight_1 weight_2 ... weight_p

where weight_1 weight_2 ... weight_p are p space-separated weights that sum to total_weight (if there are multiple options, any will be accepted).

It is guaranteed that it will be possible to find at least K different weight sums given the input data.

제한

  • 1 ≤ N ≤ 1000
  • 1 ≤ K ≤ 1000
  • Each weight is in [1, 1000000]

예제 입력 1

5
10
1 12 4 5 100

예제 출력 1

0:
1: 1
4: 4
5: 1 4
6: 1 5
9: 4 5
10: 1 4 5
12: 12
13: 1 12
16: 4 12

힌트

출처

ICPC > Regionals > Europe > Southwestern European Regional Contest > SWERC 2020-2021 연습 세션 PA번

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

출처

대학교 대회

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

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