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

19696번 - Knapsack 다국어

시간 제한메모리 제한제출정답맞힌 사람정답 비율
1 초 512 MB156383031.250%

문제

There is a housewife who recently won a prize to “shop for free as long as your shopping basket is not full” in a department store.

This housewife is given a shopping basket that can carry a maximal weight of S kilograms.

There are N item types in the department store and the i-th item is worth Vi SGD, weighs Wi kilograms, and there are Ki copies (of exactly same value and weight) of such item i.

For example, there are N = 3 item types: meat, milk, and bread; of which there are: 1 pack of meat, 3 bottles of milk, and 4 loaves of bread (see the last sample test case).

What items should the housewife take to maximize the total value of the items in her shopping basket?

입력

Your program must read from standard input.

The first line of input contains two positive integers, S and N.

The next N lines of input will each contain three integers, where the i-th line contains Vi, Wi and Ki, the value in SGD, weight in kilograms and number of the i-th item respectively.

출력

Your program must print to standard output.

Your program should print one integer, representing the maximum total value in SGD of the items that this housewife can take while ensuring the total weight does not exceed S kilograms.

제한

  • 1 ≤ S ≤ 2000
  • 1 ≤ Vi ≤ 1000000
  • 1 ≤ Wi ≤ S
  • 1 ≤ N ≤ 100000
  • 1 ≤ Ki ≤ 109

예제 입력 1

15 5
4 12 1
2 1 1
10 4 1
1 1 1
2 2 1

예제 출력 1

15

The housewife can take one of items 2, 3, 4, 5 giving a total weight of 1 +たす 4 +たす 1 +たす 2 = 8 and a total value of 2 +たす 10 +たす 1 +たす 2 = 15.

예제 입력 2

20 3
5000 15 1
100 1 3
50 1 4

예제 출력 2

5400

The housewife take one of item 1, three of item 2 and two of item 3 for a total weight of 15 × 1 + 1 × 3 + 1 × 2 = 20 and a total value of 5000 × 1 + 100 × 3 + 50 × 2 = 5400.

힌트

출처

Olympiad > National Olympiad in Informatics (Singapore) > Qualification > NOI 2018 Preliminary 2번

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

출처

대학교 대회

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

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