#CCBCHBON0000011. Summing Consecutive Integers (Summing Consecutive Integers)
Summing Consecutive Integers (Summing Consecutive Integers)
Summing Consecutive Integers
Source: beecrowd
Version: Phuoc Hung OJ Extended
Problem Statement
Read integer , then keep reading candidate values for until the first strictly positive value. Ignore zero and negative candidates. Print the sum of exactly consecutive integers beginning at inclusive.
Input
One line contains followed by 1 to 100 candidate values for ; the final candidate is the first positive one. PHOJ bounds: , candidates in , accepted in .
Output
Print one integer, the requested sum.
Subtasks
-
Subtask 1 (20%): At most 3 nonpositive candidates before the first positive ; .
-
Subtask 2 (30%): At most 15 nonpositive candidates before the first positive ; .
-
Subtask 3 (50%): At most 100 nonpositive candidates before the first positive ; .
Examples
Example 1
Input:
3 -2 0 2
Output:
7
Explanation:
Ignore nonpositive N candidates, then add exactly N integers starting from A.
Example 2
Input:
-3 0 -1 4
Output:
-6
Explanation:
Ignore nonpositive N candidates, then add exactly N integers starting from A.