DONOTHIN - Doing Nothing

Original statement in spanish at http://www.dc.uba.ar/events/icpc/download/problems/taip2011-problems.pdf

A young couple uses to make their time as productive as possible. This activity is quite stressful, so they decided to "waste" some time watching their favorite TV series.

The series has N seasons, and each season has a possibly different number of chapters according to its success, actors availability, production time and other external factors. Each chapter has a duration of exactly M minutes.

To keep up with the plot, before watching each new season, they watch, without any rest, all the chapters of all the previous seasons. This has just made them concern about how much time they will be spending with this hobby, which should keep them calm. They need your help so they don't get back to the stressful situation they had.

Input

The input contains several test cases. Each test case is described in two lines. The first line has two integers N and M representing respectively how many seasons the series has and the duration in minutes of each chapter (1 <= N <= 105, 1 <= M <= 106). The next line has N integers C_i representing how many chapters each season has sorted chronologically. (1 <= C_i <= 100 for 1 <= i <= N). The last line of the input contains the number -1 twice and should not be processed as a test case.

Output

For each test case output a single line with an integer representing the number of minutes the couple spends in watching the whole series.

Example

Input:

6 20
24 23 15 22 24 17
1 100
100
10 1000000
99 99 99 99 99 99 99 99 99 99
-1 -1

Output:

9000
10000
5445000000

Added by:Pablo Ariel Heiber
Date:2011-10-04
Time limit:1.117s
Source limit:50000B
Memory limit:1536MB
Cluster: Cube (Intel G860)
Languages:All except: ASM64
Resource:Argentinian Programming Tournament 2011

hide comments
2015-07-14 15:14:14
silly qn but listen
if they viewed first season and took rest the if they have to start with the second season then they have to watch both first and second seasons.so code it like
sum=0;res=0;
sum+=a[i]; all i's till n;
res+=sum;
output ans*m and use long long int for var's and for array use int a[10000]; to avoid sigesev
2012-06-05 14:19:45 B.R.ARVIND
first of all move this to tutorial , i wasted my 15 min :(
2012-02-09 21:02:24 gabber
just a useless ques
2012-02-04 22:12:22 Sandeep Singh Jakhar
Tutorial
2012-01-07 10:59:13 K@r+h!k
This problem does not belong here. Should be moved to tutorial.
2011-12-26 07:14:22 Aditya Muttur
what do they mean by without any rest? what is this time they take for rest. by my understanding they watch a season, then they watch all the seasons before it and then they start the next.
Which Data Type fits for C++

Last edit: 2011-12-26 08:41:16
2011-11-21 10:55:16 Vinay Saini
should be moved to tutorial.
2011-11-10 19:07:06 Supan Shah
are the outputs correct ?? i am getting 2500 for the first case ??
2011-10-24 15:46:10 Nitin Sharma
should be moved to tutorial.
2011-10-13 16:56:35 Pandian
Really doing nothing :P :P :P
© Spoj.com. All Rights Reserved. Spoj uses Sphere Engine™ © by Sphere Research Labs.