A. If at first you don't succeed...(水题)

A. If at first you don't succeed...
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output

Each student eagerly awaits the day he would pass the exams successfully. Thus, Vasya was ready to celebrate, but, alas, he didn't pass it. However, many of Vasya's fellow students from the same group were more successful and celebrated after the exam.

Some of them celebrated in the BugDonalds restaurant, some of them — in the BeaverKing restaurant, the most successful ones were fast enough to celebrate in both of restaurants. Students which didn't pass the exam didn't celebrate in any of those restaurants and elected to stay home to prepare for their reexamination. However, this quickly bored Vasya and he started checking celebration photos on the Kilogramm. He found out that, in total, BugDonalds was visited by AA students, BeaverKing — by BB students and CC students visited both restaurants. Vasya also knows that there are NN students in his group.

Based on this info, Vasya wants to determine either if his data contradicts itself or, if it doesn't, how many students in his group didn't pass the exam. Can you help him so he won't waste his valuable preparation time?

Input

The first line contains four integers — AABBCC and NN (0A,B,C,N1000≤A,B,C,N≤100).

Output

If a distribution of NN students exists in which AA students visited BugDonalds, BB — BeaverKing, CC — both of the restaurants and at least one student is left home (it is known that Vasya didn't pass the exam and stayed at home), output one integer — amount of students (including Vasya) who did not pass the exam.

If such a distribution does not exist and Vasya made a mistake while determining the numbers AABBCC or NN (as in samples 2 and 3), output 1−1.

Examples
input
Copy
10 10 5 20
output
Copy
5
input
Copy
2 2 0 4
output
Copy
-1
input
Copy
2 2 2 1
output
Copy
-1
Note

The first sample describes following situation: 55 only visited BugDonalds, 55 students only visited BeaverKing, 55 visited both of them and 55students (including Vasya) didn't pass the exam.

In the second sample 22 students only visited BugDonalds and 22 only visited BeaverKing, but that means all 44 students in group passed the exam which contradicts the fact that Vasya didn't pass meaning that this situation is impossible.

The third sample describes a situation where 22 students visited BugDonalds but the group has only 11

 which makes it clearly impossible


题意:给出a,b,c,d。表示去BugDonalds的有a个人,去BeaverKing的有b个人,两者都去的有c人,一共有d人,问,有多少人没两者都没去,如果答案为0或者是不合法的话,输出-1.

#include "iostream"
using  namespace std;
int main()
{
    int a,b,c,d;
    cin>>a>>b>>c>>d;
    if(a+b-c>=d||c>a||c>b) cout<<"-1"<<endl;
    else cout<<d-(a+b-c)<<endl;
    return 0;
}

猜你喜欢

转载自blog.csdn.net/qq_41874469/article/details/80789392