Algorithm


Problem link- https://www.spoj.com/problems/DONOTHIN/

DONOTHIN - Doing Nothing

no tags 

 

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

 

Code Examples

#1 Code Example with C++ Programming

Code - C++ Programming

#include <iostream>
#include <cstdio>
#include <vector>
#include <cstring>
#include <algorithm>
#include <cmath>
#include <sstream>
#include <map>
#include <list>

using namespace std;

int main(){
	long long n,m,total;
	while(true){
		total=0;
		scanf("%lld%lld",&n,&m);
		if(n==-1&&m==-1)break;
		while(n--){
			//cout<<n<<endl;
			long long  temp;
			scanf("%lld",&temp);
			temp=temp*m*(n+1);
			total+=temp;
		}
		printf("%lld\n",total);
	}
	return 0;
}
Copy The Code & Try With Live Editor

Input

x
+
cmd
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

x
+
cmd
9000
10000
5445000000
Advertisements

Demonstration


SPOJ Solution-Doing Nothing-Solution in C, C++, Java, Python

Previous
SPOJ Solution - Test Life, the Universe, and Everything - Solution in C, C++, Java, Python