#C8867. Feast Time

    ID: 52896 Type: Default 1000ms 256MiB

Feast Time

Feast Time

You have been tasked by the king to prepare a royal feast. There are n dishes, and each dish i requires a given preparation time. The king especially loves the dish numbered k and has requested it to be served m times. Given a total available time t, your task is to determine if it is feasible to serve the favorite dish m times. If it is feasible, output the remaining time after preparing the requested servings; otherwise, output IMPOSSIBLE.

The required time for the favorite dish is given by the formula:

\(\text{required time} = \text{preparation_times}[k-1] \times m\)

If \(\text{required time} \le t\), then the output is \(t - \text{required time}\); otherwise, output IMPOSSIBLE.

inputFormat

The input is read from standard input and contains two lines:

  • The first line contains four space-separated integers: n (number of dishes), k (favorite dish number), m (number of times the favorite dish must be served), and t (total available time).
  • The second line contains n space-separated integers, where the ith integer is the time required to prepare the ith dish.

outputFormat

Output to standard output a single line containing either an integer (the remaining time after preparing the favorite dish m times) or the string IMPOSSIBLE if the available time is insufficient.

## sample
5 3 4 300
10 20 30 40 50
180

</p>