제출 #886846

#제출 시각아이디문제언어결과실행 시간메모리
886846rafcKnapsack (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 print(curr_total) if __name__ == '__main__': main()
#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...