The Contest Contest 1 P2 - A Typical CCC Senior Problem

View as PDF

Submit solution


Points: 10 (partial)
Time limit: 1.5s
Java 3.0s
Python 3.0s
Memory limit: 512M

Author:
Problem type

To organize the upcoming CCC, Troy is creating test data for the problems! The test data for one question consists of a list of N integers a1,,aN. Unfortunately, the CCC Grader requires that test cases be manually entered into the system. Troy knows that this will be really tedious, so he starts right away.

However, the CCC Grader has another weird bug! When Troy submits the test case, the system scans the list in order from left to right. Whenever it comes across an integer d, the offending integer and the previous xd integers are removed from the test case. If there are less than xd integers currently preceding the offending integer, all integers before the offending integer are removed.

Knowing that this year's CCC is in jeopardy, Troy asks you to perform the following task: For each possible value of d from 1 to K, can you determine the sum of the integers in the resulting test case?

Constraints

2KN106

1aiK

1xiN

Subtask 1 [20%]

N2×103

Subtask 2 [40%]

xi=1

Subtask 3 [40%]

No additional constraints.

Input Specification

The first line of input contains two integers N and K.

The next line contains N integers a1,,aN.

The next line contains K integers x1,,xK.

Output Specification

Output K lines, where the kth line is the sum of the integers in the resulting test case if d=k.

Sample Input 1

Copy
5 3
3 2 1 3 1
1 2 1

Sample Output 1

Copy
3
5
3

Explanation for Sample 1

When d=1, we have x1=1. We'll denote the resultant test case as a list b. Initially b=[3,2,1,3,1].

At i=3, a3=1=d so we remove d and the preceeding element from b. b now becomes [3,3,1]

At i=5, a5=1=d so we remove d and the preceeding element from b. b now becomes [3]

b=[3] has a sum of 3 so this is our answer when d=1.

Sample Input 2

Copy
10 5
2 4 4 1 3 2 2 3 1 4
2 1 2 3 8

Sample Output 2

Copy
11
16
11
6
26

Comments

There are no comments at the moment.