Candy Totals

View as PDF

Submit solution

Points: 3
Time limit: 2.0s
Memory limit: 64M

Author:
Problem type
Allowed languages
Java

Justin has just bought some halloween candy for N days (only for himself to eat, of course) and he has already planned out how many candies to eat each day. However, he wants to know how many candies he will eat in total for the first K days. Can you figure it out for him?

Input Specification

The first line will have integer N, the number of days that Justin bought candy for. There will be between 0 and 100 days, inclusive.

The next N lines will have one integer each, representing how many candies he eats on that specific day. These values will also be in between 0 and 100, inclusive.

The final line will have integer K, the value that you will use to answer Justin's question. This value will be between 0 and N, inclusive.

Output Specification

One integer, the total number of candies he will eat for the first K days.

Sample Input 1

7
3
6
4
9
2
0
10
4

Sample Output 1

22

Sample Explanation 1

For the first 4 days, Justin eats 3, 6, 4, and 9 candies, so the total number of candies he eats in these days would be 22.

Sample Input 2

6
9
9
2
5
4
8
2

Sample Output 2

18

Sample Explanation 2

On the first day, Justin eats 9 candies, and on the second day he also eats 9 candies so he eats a total of 18 candies.


Comments

There are no comments at the moment.