#B3779. Seat Swap Energy Calculation
Seat Swap Energy Calculation
Seat Swap Energy Calculation
During a self-study class, students are allowed to change seats with one another. zyl wants to switch to a desk in the row behind her. However, to do so she must swap seats sequentially with n students. Each desk holds a number of books. In every swap, the books present on both desks are exchanged.
zyl initially has x books on her desk. Every time she swaps seats with a student whose desk has ai books, the energy consumed for that swap is the sum of the books on her desk and the other student's desk. Note that after the swap, zyl's desk will have ai books. Therefore, if the sequence of book counts on the desks of the students she swaps with is \(a_1, a_2, \dots, a_n\), then the total energy consumed is:
\[ (x + a_1) + (a_1 + a_2) + \cdots + (a_{n-1} + a_n)\]Your task is to compute the total energy consumed after all swaps.
inputFormat
The first line contains two integers n and x (\(1 \leq n \leq 10^5\), \(1 \leq x \leq 10^9\)) representing the number of students to swap with and the number of books initially on zyl's desk respectively.
The second line contains n integers \(a_1, a_2, \dots, a_n\) (\(1 \leq a_i \leq 10^9\)) where \(a_i\) is the number of books on the desk of the ith student.
outputFormat
Output a single integer which is the total energy consumed after performing all the swaps.
sample
1 5
3
8