Woburn Challenge 2015-16 Round 2 - Junior Division
As part of his intensive Jedi training at the hands of Master Yoda in the Dagobah system, Luke has been given the task of moving some rocks. That may sound simple, but he'll have to move them with his mind, using the power of the Force! Also, some of the rocks are rather heavy.
Yoda has laid out ~N~ ~(1 \le N \le 100)~ rocks on the ground, with the ~i~-th rock having a mass of ~W_i~ ~(1 \le W_i \le 100)~ pounds. He's instructed Luke to move all of them to another location, one at a time. Unfortunately, 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~ ~(1 \le M \le 100)~ pounds.
Assuming that Luke tries his best and moves as many of the rocks as he can, what's the total mass of the rocks that he'll lift?
The first line of input consists of two space-separated integers ~N~ and
The next ~N~ lines each consist of a single integer ~W_i~, for ~i = 1 \dots N~.
Output a single integer – the total mass of rocks that Luke can lift with the force.
6 8 4 9 8 12 7 1
The ~2~nd and ~4~th rocks are too heavy for Luke, but he can lift the remaining ~4~ rocks, which have a total mass of ~4 + 8 + 7 + 1 = 20~ pounds.