#K84572. Total Water Bottles Collection
Total Water Bottles Collection
Total Water Bottles Collection
You are given ( N ) checkpoints and an array ( W ) where the ( i )-th element ( W_i ) represents the number of water bottles at checkpoint ( i ). You are also given an integer ( M ) indicating that Tom will collect water bottles from the first ( M ) checkpoints. Your task is to compute the total number of water bottles collected, which can be represented as:
[ \sum_{i=1}^{M} W_i ]
Note that the checkpoints are 1-indexed.
inputFormat
The input is read from standard input (stdin). The format is as follows:
- The first line contains an integer ( N ), the total number of checkpoints.
- The second line contains ( N ) space-separated integers, where the ( i )-th integer is the number of water bottles at the ( i )-th checkpoint.
- The third line contains an integer ( M ), indicating the number of checkpoints from which bottles are collected.
outputFormat
Output a single integer which is the sum of water bottles collected from the first ( M ) checkpoints. The output should be written to standard output (stdout).## sample
5
2 4 8 3 1
3
14