Lawnmower
Time limit1sMemory limit1024 MB
Simulate a lawn that grows each morning and is mowed b_j times per day, reporting the total remaining grass height after each day.
- Level
Medium6 of 10
- Topics
- Sorting, Prefix sum, Binary search, Implementation
- Solved
- No attempts yet
Problem
There is a lawn in front of Martynas's house. The lawn can be viewed as a line of centimeters, with one tuft of grass growing at every centimeter. The tuft at position () has height centimeters.
The grass has never been cut, so it is hard to even take a walk across the lawn, let alone have a picnic.
Martynas bought a lawnmower and plans to cut most of the grass over days. Day () proceeds as follows, in order:
- Morning: every tuft that is not yet fully cut () grows by .
- Day: Martynas drives the lawnmower across the lawn times. Each pass reduces the height of every uncut tuft by (a height never drops below ).
- Evening: he counts the total height of grass still left uncut.
For example, suppose the lawn is long () and the tuft heights are . Martynas works for days, driving across the lawn times on the first day and time on the second day.
On the morning of day 1 every tuft grows by , giving . During the day he mows twice, so each tuft loses , leaving ; in the evening of grass remains.
On the morning of day 2 only the tufts that still have grass grow (the first and third stay at ), giving . He mows once, leaving ; in the evening remains again.
Given the initial state of the lawn and the mowing plan for days, compute the total height of grass left uncut in the evening of each of the days.
Input
- The first line contains an integer — the length of the lawn.
- The second line contains space-separated integers () — the heights of the grass tufts.
- The third line contains an integer — the number of days Martynas mows the grass.
- The fourth line contains space-separated integers () — the number of times the lawn is mowed on day .
Output
Print lines. Line () must contain a single integer — the total height of grass (in centimeters) left uncut at the end of day .
Constraints
- ()
- ()
Hint
Note that the computation may require a -bit integer type (long long in C/C++).