Navi is a famous shopkeeper in his locality. He gives discounts to his regular…
- User
Navi is a famous shopkeeper in his locality. He gives discounts to his regular customers. Some new rules have been made due to which he is in trouble. According to the new rules, any shopkeeper can sale his items to only one customer in a day. But every customer has some issues like the total money they have or the total weight they can handle at a time or number of items they are interested in. Navi’s friend has decided to help Navi and he promised him that he will purchase items from his shop daily and try to maximize his sale in terms of total price with satisfying the count of items and weight of the items . He will give his requirements as Wmax (maximum weight he can carry) and C (maximum count of the items he can carry). Now Navi is interested in knowing the total price of the items he can sell. Input First line of input will contain D (total number of days). Then for each day first line will contain N (Number of items) . Next each N lines will contains two integers P (price of ith item on that day) and W(weight of ith item on that day) separated by a space. Last line for the input of the particular day will contain Wmax and C separated by a space.
Output For each day output “For Day #day_number:” then in next line print the maximum total price. If his friend is not able to purchase any of the item then print -1. Constraints 1 < = D < = 10
1 < = N < = 16
1 < = C < = 20
1 < = Pi , Wi , Wmax < = 10^9
SAMPLE INPUT 1 3 10 20 20 30 30 40 50 2
SAMPLE OUTPUT For Day #1: 30
Explanation
He will buy first and second item.
Assistant
import sys def main(): D = int(sys.stdin.readline()) for day in range(1, D+1): N = int(sys.stdin.readline()) items = [] for _ in range(N): p, w = map(int, sys.stdin.readline().split()) items.append((p, w)) Wmax, C = map(int, sys.stdin.readline().split()) max_price = -1 for mask in range(1, 1 << N): count = bin(mask).count('1') if count > C: continue sum_p = 0 sum_w = 0 for i in range(N): if mask & (1 << i): sum_p += items[i][0] sum_w += items[i][1] if sum_w <= Wmax and sum_p > max_price: max_price = sum_p print(f"For Day #{day}:") print(max_price if max_price != -1 else -1) 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.