Testing Pants for sadnesscrawling in process ... crawling failed Time limit:MS Memory Limit:262144KB 64bit IO Format:% I64d &%i64u
SubmitStatus Practice codeforces 103A
Description
The average miner Vaganych took refresher courses. As soon as a miner completes the courses, he should take exams. The hardest one is a computer test called "Testing Pants for Sadness".
The test consists of n questions; The questions is answered strictly in the order in which they is given, from question1 to question n< /c3>. Questioni contains ai answer variants, exactly one of them is correct.
A Click is regarded as selecting any answer in any question. The goal is to select the correct answer for each of theN questions. If Vaganych selects a wrong answer for some question, then all selected answers become unselected and the test starts from The very beginning, from question1 again. But Vaganych remembers everything. The order of answers for each question and the order of questions remain unchanged, as well as the question and answers th Emselves.
Vaganych is very smart and its memory is superb, yet he's unbelievably unlucky and knows nothing whatsoever about the TES T ' s theme. How many clicks would he have a perform in the worst case?
Input
The first line contains a positive integer n (1?≤? N? ≤?100). It is the number of questions in the test. The second line contains space-separatedn positive integers ai (1?≤? Ai-≤?109), the number of answer variants to question I.
Output
Print a single number-the minimal number of clicks needed to pass the test it the worst-case scenario.
%lld Specificator to read or write 64-bit integers inс++. It is preferred to use the CIN, cout streams or the%i64d specificator.
Sample Input
Input
21 1
Output
2
Input
22 2
Output
5
Input
110
Output
10
Sample Output
Hint
Note to the second sample. In the worst-case scenario you'll need five clicks:
- The first click selects the first variant to the first question, this answer turns out to be wrong.
- The second click selects the second variant to the first question, it proves correct and we move on to the second question ;
- The third click selects the first variant to the second question, it's wrong and we go back to question 1;
- The fourth click selects the second variant to the first question, it proves as correct as it is and we move on to the SE Cond question;
- The fifth click selects the second variant to the second question, it proves correct, and the test is finished.
Reference code:
#include <stdio.h> #define LL __int64int main () {int n;ll a[105];ll sum;while (~scanf ("%d", &n)) {sum=0;for (int i =1;i<=n;i++) scanf ("%i64d", &a[i]), for (int i=1;i<=n;i++) sum+= (i-1) * (a[i]-1) +a[i];p rintf ("%i64d\n", sum);} return 0;}
Copyright NOTICE: This article for Bo Master original article, casually reproduced.
Codeforces 130a-testing Pants for sadness (Problem solving report)