No.633 Bus Fare
タグ : / 解いたユーザー数 254
作問者 :
horiesiniti
/ テスター :
romitagari
Problem Statement
A certain town operates a bus that stops once at each district.
The town has bus stops numbered $1$ to $n$, and the bus proceeds through the bus stops in order from 1 to n.
A passenger pays a fare of $a_i$ yen to go from bus stop $i$ to bus stop $i+1$.For bus stops $i$,$j$, the fare for one passenger to go from $i$ to $j$ is $a_i$+$a_{i+1}$+$\dots$+$a_{j-1}$ yen.
The data is given with $b_i$ as the number of people who got off at bus stop $i$ and $c_i$ as the number of people who got on there.
When the bus arrives at bus stop $i$, it first lets $b_i$ people off and then takes $c_i$ people on.
From $a_i$,$b_i$,$c_i$, find the total fare paid by all passengers.
(*Notes) The bus arrives at bus stop 1 with no passengers on board at first. $b_1$ and $c_n$ are 0. All passengers get off at bus stop $n$. No more passengers get off than are on the bus. The bus can carry infinitely many passengers.
Input
$n$
$a_1$
$\dots$
$a_{n-1}$
$b_1$ $c_1$
$\dots$
$b_i$ $c_i$
$\dots$
$b_n$ $c_n$
The number of bus stops $n$ is given on one line.
The following $n-1$ lines give ai.
The following $n$ lines give $b_i$ and $c_i$: the number of people $b_i$ who got off and the number of people $c_i$ who got on at bus stop $i$.
$2 \le n \le 100$
Fare of each section
$0 \le ai \le 100$
Number of people getting off and on
$0 \le bi \le バス停iに到着時バスに乗っている人数$
$0 \le ci \le 100$
Output on one line the total $ans$ of the fares paid by all passengers (do not forget the newline).
Output
ans Print a newline at the end.
Sample
Sample 1
Input
4 11 7 3 0 3 2 4 1 0 4 0
Output
80
At bus stop 1, 3 people got on. At bus stop 2, 2 people got off and 4 people got on. At bus stop 3, 1 person got off. At bus stop 4, 4 people got off. The total fare paid by all passengers is 80.
提出するには、Twitter 、GitHub、 Googleもしくは右上の雲マークをクリックしてアカウントを作成してください。