Editorial for WC '15 Contest 2 J2 - The Empire Strikes Back


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.

Much like the first problem, this one tests basic skills in interpretation and implementation. The difference here is that neither looping nor if-statements can be avoided. Given two integers N and M, the question asks us to take N integer masses and add up all the ones which are less than or equal to M. If you solved the last problem, chances are you'll have no trouble with looping/if-statements and input. This is as easy as looping N times to read in the masses one by one, and having one if-statement within the loop to check if the number that was just read in is at most M.

Note that we don't have to overcomplicate the solution by storing the numbers into arrays. We can simply process the input one by one as we go, since M is given beforehand and a number won't be needed again after we're done with it for the first time. The only part that you might trip up on is interpreting the phrase "Luke's control of the Force is only strong enough to allow him to lift a rock if its mass is no larger than M." This means that we should add the number if it's less than or equal to (\le) M, and not if it's strictly less than (<) M.


Comments

There are no comments at the moment.