Editorial for LCC '24 Contest 1 J2 - Shopping Spree


Remember to use this editorial only when stuck, and not to copy-paste code from it. Please be respectful to the problem author and editorialist.
Submitting an official solution before solving the problem yourself is a bannable offence.

Author: ninja888

Subtask 1

Since N = 1, there is only one item to take. If you have the money, you always buy it, otherwise you print 0 since you can't purchase it.

Time Complexity: O(1)

Subtask 2

After taking input for N and W, simply iterate through each c_i and v_i. If the current W is greater than c_i, simply add v_i to a variable; otherwise, continue to the next iteration of the loop. The answer is the total sum of all the v_i located in the stored variable.

Time Complexity: O(N)


Comments

There are no comments at the moment.