WBC '25 P3 - Scoring Pictures
View as PDFWelcome Back Contest: 2025 Problem 3
Sally loves taking photos of the wonderful buildings in her town! There are buildings standing next to each other, numbered
to
from left to right. She wants assign a "view score" for the view of the buildings using her camera. Sally's camera can capture up to
adjacent buildings together in a single photo. In order to score the view the buildings, she first takes pictures of all sets of
adjacent buildings. By doing this, she will have taken
photos. For each photo, she defines its individual "score" as the sum of the heights of each building in the photo. She then takes the sum of all scores and calls it the view score.
However, the heights of various buildings may change due to construction. In total, updates happen to various buildings. For each of the
updates, a building increases their height by some amount. Since Sally wants to keep her view score up to date, after each update, she recomputes the view score by repeating her initial process.
Help Sally calculate the view score after each of the updates, as well as the original score.
Input Specification
The first line contains the integers ,
, and
, each separated by a single space.
The next line contains the intial heights of the buildings, each separated by a single space. The
-th building has an initial height of
.
The next lines contain
integers each,
and
, indicating that the
-th building increased by a height of
.
Output Specification
On the first line, output the initial view score. For each of the updates, output the new view score on its own line.
Subtasks
Subtask 1 [50%]
Subtask 2 [50%]
No additional constraints
Sample Input 1
5 3 2
3 5 2 1 4
2 1
3 2
Output for Sample Input 1
25
27
33
Explanation of Output for Sample Input 1
Initially, there are buildings of heights
.
First, Sally takes photos of all possible groupings of adjacent buildings, which are of
,
, and
. The sums of the pictures are
,
, and
. Thus, the view score is
.
After the first update, the nd building increased its height by
. The
buildings now have a heights of
. The new view score is
.
After the second update, the rd building increased its height by
. The
buildings now have a heights of
. The new view score is
.
Sample Input 2
4 3 3
1 1 1 1
4 1
1 1
2 1
Output for Sample Input 2
6
7
8
10
Sample Input 3
6 3 1
1 2 3 4 5 6
1 1
Output for Sample Input 3
42
43
Comments