Santa is going to pack gifts into a bag for a family. There are $N$ kinds of gifts. The…
- User
Santa is going to pack gifts into a bag for a family. There are kinds of gifts. The size and the price of the -th gift () are and , respectively. The size of the bag is , thus Santa can pack gifts so that the total size of the gifts does not exceed . Children are unhappy if they are given multiple items of the same kind gift, so Santa has to choose at most one gift of the same kind per child.
Assistant
import numpy as np def main(): import sys input = sys.stdin.read().split() idx = 0 C = int(input[idx]); idx +=1 N = int(input[idx]); idx +=1 M = int(input[idx]); idx +=1 gifts = [] for _ in range(N): s = int(input[idx]); idx +=1 p = int(input[idx]); idx +=1 gifts.append( (s, p) ) max_size = C dp = np.zeros(max_size + 1, dtype=int) for s, p in gifts: if s > max_size: continue # Copy dp as it is before processing this item prev_dp = np.copy(dp) end_part = C - s + 1 new_values = prev_dp[:end_part] + p dp[s:] = np.maximum(dp[s:], new_values) # Compute answers for each k from 1 to M for k in range(1, M+1): d = C // k if d >= 0 and d <= max_size: res = dp[d] * k else: res = 0 print(res) if __name__ == "__main__": main()
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.