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

27119번 - Milk Measuring 다국어채점 준비 중

시간 제한메모리 제한제출정답맞힌 사람정답 비율
1 초 1024 MB0000.000%

문제

Farmer John must measure Q quarts of his finest milk and deliver it in one big bottle to a customer. He fills that bottle with exactly the number of quarts that the customer orders.

Farmer John has always been frugal. He is at the cow hardware store where he must purchase a set of pails with which to measure out Q quarts of milk from his giant milk tank. Since the pails each cost the same amount, your task is to figure out a minimal set of pails Farmer John can purchase in order to fill a bottle with exactly Q quarts of milk.

To measure out milk, F.J. may completely fill a pail from the tank and pour it into the bottle. He can never remove milk from the bottle or pour milk anywhere except into the bottle. With a one-quart pail, FJ would need only one pail to create any number of quarts in a bottle. Other pail combinations are not so convenient.

Determine the optimally small number of pails to purchase, given the guarantee that at least one solution is possible for all contest input data.

입력

  • Line 1: integer Q (1 ≤ Q ≤ 20000): number of quarts to be measured out
  • Line 2: integer P (1 ≤ P ≤ 100): number of pails in the store
  • Lines 3..P+2: integer pail_value (1 ≤ pail_value ≤ 10000), the number of quarts a pail holds

출력

The output is a single line that contains:

  • the minimum number of pails required to measure out the desired number of quarts, followed by:
    • a SORTED list (from smallest to largest) of the capacity of each of the required pails

제한

예제 입력 1

11
3
3
5
7

예제 출력 1

2 3 5

힌트

출처

Olympiad > USA Computing Olympiad > 1998-1999 Season > USACO National Championship 1999 > Contest 2번

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

출처

대학교 대회

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

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