#SRD0000013. Cuộc đột kích đàn bò (Time to Raid Cowavans)
Bài tập thuộc lộ trình
Mục lục đề ⌄
Cuộc đột kích đàn bò (Time to Raid Cowavans)
Time to Raid Cowavans
Source: Codeforces
Version: Phuoc Hung OJ Extended
Problem Statement
There are cows in a row, numbered from to . Cow has weight . The aliens investigate independent raiding plans, each defined by positive integers .
For plan , they select cows at positions
as long as the position does not exceed . Find the sum of weights of all selected cows. Every plan is a separate query: cows are not removed and indices are never renumbered. If , only one cow is selected.
Input
The first line contains ; the second contains weights ; the third contains . The next lines contain a b.
Output
Output the total weight for each plan on its own line, in input order.
Subtasks
- Subtask 1 (10 points): ; ; ; .
- Subtask 2 (15 points): ; ; ; .
- Subtask 3 (30 points): ; ; ; .
- Subtask 4 (45 points): ; ; ; .
Examples
Input
4
2 3 5 7
3
1 3
2 3
2 2
Output
9
3
10
Explanation
Plan (1,3) takes positions , giving . Plan (2,3) takes only position , giving . Plan (2,2) takes positions , giving .