# PROBLEM LINK:

Practice

Contest: Division 1

Contest: Division 2

Contest: Division 3

Contest: Division 4

* Author:* iceknight1093

*tabr*

**Tester:***iceknight1093*

**Editorialist:**# DIFFICULTY:

885

# PREREQUISITES:

None

# PROBLEM:

The Child of Prophecy has rung K out of N bells.

Her initial mana level is P, and you know how much each bell increases it by.

What’s her current mana level?

# EXPLANATION:

Doing some simple casework, the different types of increases can all be handled separately.

- First, if K \leq X, all the bells rung will provide an increase of +10.

So, the final mana level is P + 10\cdot K. - Next, if X \lt K \lt N, the first X bells will provide an increase of +10, and the remaining will provide an increase of +5.

There are K-X bells after the first X, and so the mana level in this case is

P + 10\cdot X + 5\cdot (K-X)

- Finally, if K = N, the second point above applies; but there’s a further increase of 20 to the mana level.

In this case, the answer is

P + 10\cdot X + 5\cdot (N-X) + 20

Using `if`

conditions to compare the values of K and X, all three conditions can be handled separately.

# TIME COMPLEXITY

\mathcal{O}(1) per testcase.

# CODE:

## Editorialist's code (Python)

```
for _ in range(int(input())):
n, x, k, p = map(int, input().split())
if k <= x: print(p + 10*k)
elif k < n: print(p + 10*x + 5*(k - x))
else: print(p + 10*x + 5*(n-x) + 20)
```