A - Bubbler Editorial /

Time Limit: 2 sec / Memory Limit: 1024 MB

配点 : 9

問題文

レストランに来た高橋君は A 円のランチと B 円のドリンクバーを注文しようとしています。
高橋君は C 円引きのドリンクバー割引券を持っており、割引券を利用すると合計 A + B - C 円で注文することができます。
一方、ランチとドリンクバーのセットメニューを D 円で注文することもできますが、割引券を適用することはできません。
高橋君がランチとドリンクバーの両方を注文するのに必要な最小の金額を出力してください。

制約

  • 1 \leq A \leq 1000
  • 1 \leq C \lt B \leq 1000
  • 1 \leq D \leq 1000
  • 入力は全て整数である。

入力

入力は以下の形式で標準入力から与えられる。

A B C D

出力

高橋君がランチとドリンクバーの両方を注文するのに必要な最小の金額を出力せよ。


入力例 1

600 200 100 750

出力例 1

700

割引券を使ったときの金額は 600 + 200 - 100 = 700 円、セットメニューを注文したときの金額は 750 円なので、高橋君は 700 円でランチとドリンクバーを注文することができます。


入力例 2

600 200 100 650

出力例 2

650

割引券を使ったときの金額は入出力例 1 と同様に 700 円ですが、セットメニューを注文したときの金額は 650 円なので、答えは 650 円になります。


入力例 3

800 200 100 900

出力例 3

900

Score : 9 points

Warning

Do not make any mention of this problem until October 2, 2021, 6:00 p.m. JST. In case of violation, compensation may be demanded. After the examination, you can reveal your total score and grade to others, but nothing more (for example, which problems you solved).

Problem Statement

In a restaurant, Takahashi is about to order an A-yen lunch and a B-yen free refill service. (Yen is the Japanese currency.)
He has a coupon that gives C-yen discount on the free refill service, allowing him to order both for a total of A + B - C yen.
On the other hand, a set menu of the lunch and the free refill service is also available for D yen, but the coupon cannot be applied to this.
Print the minimum total amount of money needed for Takahashi to order both the lunch and the free refill service.

Constraints

  • 1 \leq A \leq 1000
  • 1 \leq C \lt B \leq 1000
  • 1 \leq D \leq 1000
  • All values in input are integers.

Input

Input is given from Standard Input in the following format:

A B C D

Output

Print the minimum total amount of money needed for Takahashi to order both the lunch and the free refill service, as an integer.


Sample Input 1

600 200 100 750

Sample Output 1

700

They cost 600 + 200 - 100 = 700 yen when he uses the coupon, and 750 yen when he orders the set menu, so he needs to pay 700 yen to order both.


Sample Input 2

600 200 100 650

Sample Output 2

650

Again they cost 700 yen when he uses the coupon, but the set menu costs 650 yen this time, so the answer is 650 yen.


Sample Input 3

800 200 100 900

Sample Output 3

900