Submission #886846

#TimeUTC-0UsernameProblemLanguageResultExecution timeMemory
8868462023-12-13 03:57:13rafcKnapsack (NOI18_knapsack)Pypy 3
12 / 100
30 ms18372 KiB
import sys
def main():
read = sys.stdin.readline
s, n = (int(i) for i in read().split())
values = []
weights = []
quantities = []
sorted_values = []
for index in range(n):
v_i, w_i, k_i = (int(i) for i in read().split())
values.append(v_i)
weights.append(w_i)
quantities.append(k_i)
sorted_values.append((v_i / w_i, index))
sorted_values.sort(reverse=True)
curr_weight = 0
curr_total = 0
for i in range(len(sorted_values)):
_, idx = sorted_values[i]
value = values[idx]
weight = weights[idx]
quantity = quantities[idx]
remaining_weight = s - curr_weight
quantity_to_grab = min(remaining_weight // weight, quantity)
curr_total += quantity_to_grab * value
curr_weight += quantity_to_grab * weight
 
הההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההה
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...