CodeForces - 991A(思维题)

题目链接:https://cn.vjudge.net/problem/CodeForces-991A

题目描述:

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 A students, BeaverKing — by B students and C students visited both restaurants. Vasya also knows that there are N 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 — A , B , C and N (0≤A,B,C,N≤1000≤A,B,C,N≤100 ).

Output

If a distribution of NN students exists in which A students visited BugDonalds, B — BeaverKing, C — 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 A , B , C or N (as in samples 2 and 3), output −1−1 .

Examples

Input

10 10 5 20

Output

5

Input

2 2 0 4

Output

-1

Input

2 2 2 1

Output

-1

Note

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

In the second sample 2 students only visited BugDonalds and 2 only visited BeaverKing, but that means all 4 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 2 students visited BugDonalds but the group has only 1 which makes it clearly impossible.

题目大意:

给定A,B,C,N,四个数。A代表去第一家餐厅的学生数,B代表去第二家的人数值,C代表两家都去的人数值,不及格的同学则在家(一直在家的学生大于等于1)。N代表猜测的学生人数,若N能否满足ABC与不及格在家的关系,可以,输出在家的学生人数,否则,输出-1

代码:

#include<cstdio>
#include<cstring>
#include<queue>
#include<algorithm>
#include<iostream>
using namespace std;
int main()
{
    int A,B,C,N;
    int sum;
    while(scanf("%d%d%d%d",&A,&B,&C,&N)!=EOF)
    {
        sum=0;
        if(A+B-C>=N)
            printf("-1\n");
        else if(A<C||B<C)//这一判断条件比较容易忽略,因为这个w了一次
            printf("-1\n");
        else
        {
            sum=N-(A+B-C);
            printf("%d\n",sum);
        }
    }
    return 0;
}

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值