Problem:
Score : 100 points

Problem Statement

There is a hotel with the following accommodation fee:

X yen (the currency of Japan) per night, for the first K nights

Y yen per night, for the (K+1)-th and subsequent nights

Tak is staying at this hotel for N consecutive nights.
Find his total accommodation fee.

Constraints

1 \leq N, K \leq 10000

1 \leq Y < X \leq 10000

N,\,K,\,X,\,Y are integers.

Input

The input is given from Standard Input in the following format:

N
K
X
Y

Output

Print Tak's total accommodation fee.

Sample Input 1

5
3
10000
9000

Sample Output 1

48000

The accommodation fee is as follows:

10000 yen for the 1-st night

10000 yen for the 2-nd night

10000 yen for the 3-rd night

9000 yen for the 4-th night

9000 yen for the 5-th night

Thus, the total is 48000 yen.

Sample Input 2

2
3
10000
9000

Sample Output 2

20000

Solution in C# (Mono 4.6.2.0) (judge verdict: Runtime Error)

using System;
using System.Collections.Generic;
using System.Linq;

namespace ABC044_C
{
    class Program
    {

        static void Main()
        {
            var array = Utility.ReadIntArray();
            var N = array[0];
            var A = array[1];
            var X = Utility.ReadIntArray();

            var dp = new long[N + 1, N + 1, (N + 1) * A];
            dp[0, 0, 0] = 1;
            for (var i = 0; i < N; i++)
            {
                for (var j = 0; j < N; j++)
                {
                    for (var k = 0; k < dp.GetLength(2); k++)
                    {
                        if (dp[i, j, k] != 0)
                        {
                            dp[i + 1, j, k] += dp[i, j, k];
                            dp[i + 1, j + 1, k + X[i]] += dp[i, j, k];
                        }
                    }
                }
            }
            long ans = 0;
            for (var i = 1; i <= N; i++)
            {
                ans += dp[N, i, i * A];
            }
            Console.WriteLine($"{ans}");
        }
    }
    public static class Utility
    {
        public static string ReadString() => Console.ReadLine();
        public static string[] ReadStringArray() => ReadString().Split(' ');
        public static int ReadInt() => int.Parse(ReadString());
        public static int[] ReadIntArray() => ReadStringArray().ParseInt().ToArray();
        public static IEnumerable<int> ParseInt(this IEnumerable<string> source) => source.Select(v => int.Parse(v));
    }
}