CF991A.If at first you don't succeed...
入门
通过率:0%
时间限制:1.00s
内存限制:256MB
AC君温馨提醒
该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。
题目描述
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?
每位学生都热切期盼着自己成功通过考试的那一天。因此,瓦夏已经准备好庆祝了,但遗憾的是,他没能通过考试。然而,瓦夏同班的许多同学却更加幸运,他们在考试后举行了庆祝活动。
其中一些人在“BugDonalds”餐厅庆祝,另一些人则在“BeaverKing”餐厅庆祝,而最成功的那些同学甚至来得及在两家餐厅都进行了庆祝。那些未能通过考试的学生则没有在上述任何一家餐厅庆祝,而是选择待在家里准备补考。然而,这种单调的生活很快让瓦夏感到厌烦,于是他开始在“Kilogramm”网站上浏览庆祝照片。他发现:总共有 A 名学生光顾了 BugDonalds 餐厅,B 名学生光顾了 BeaverKing 餐厅,而有 C 名学生同时光顾了这两家餐厅。瓦夏还知道,他所在的班级一共有 N 名学生。
根据这些信息,瓦夏希望判断自己的数据是否存在矛盾;若无矛盾,则进一步算出他所在班级中未通过考试的学生人数。你能帮他解决这个问题吗?这样他就不会白白浪费宝贵的备考时间了。
输入格式
The first line contains four integers — A, B, C and N (0≤A,B,C,N≤100).
第一行包含四个整数——A、B、C 和 N(0≤A,B,C,N≤100)。
输出格式
If a distribution of N 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.
如果存在一种 N 名学生的分布情况,其中 A 名学生去了 BugDonalds 餐厅,B 名学生去了 BeaverKing 餐厅,C 名学生两家餐厅都去了,且至少有一名学生待在家中(已知 Vasya 考试未通过,留在了家中),则输出一个整数——考试未通过的学生总人数(包括 Vasya)。
如果不存在这样的分布,且 Vasya 在确定数字 A、B、C 或 N 时出现了错误(如样例 2 和样例 3 所示),则输出 −1。
输入输出样例
输入#1
10 10 5 20
输出#1
5
输入#2
2 2 0 4
输出#2
-1
输入#3
2 2 2 1
输出#3
-1
说明/提示
The first sample describes following situation: 5 only visited BugDonalds, 5 students only visited BeaverKing, 5 visited both of them and 5 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.
第一个样例描述了如下情况:有 5 名学生只去了 BugDonalds,5 名学生只去了 BeaverKing,5 名学生两家都去了,还有 5 名学生(包括 Vasya)没有通过考试。
第二个样例中,有 2 名学生只去了 BugDonalds,2 名学生只去了 BeaverKing;但这意味着小组中全部 4 名学生都通过了考试,与 Vasya 未通过考试的事实矛盾,因此该情况不可能发生。
第三个样例描述了一种情况:有 2 名学生去了 BugDonalds,但小组中仅有 1 人,这显然不可能。
输入解题思路,AI测评打分。不知道怎么写?