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 — AA, BB, CC and NN (0≤A,B,C,N≤1000≤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 AA, BB, CC 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.
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
某涉密单位下发了某种票据,并要在年终全部收回。
每张票据有唯一的 ID 号。全年所有票据的 ID 号是连续的,但 ID 的开始数码是随机选定的。
因为工作人员疏忽,在录入 ID 号的时候发生了一处错误,造成了某个 ID 断号,另外一个 ID 重号。
你的任务是通过编程,找出断号的 ID 和重号的 ID。
假设断号不可能发生在最大和最小号。
Input
要求程序首先输入一个整数 NN (N<100)(N<100) 表示后面数据行数。
接着读入 NN 行数据。
每行数据长度不等,是用空格分开的若干个(不大于 100 个)正整数(不大于 100000),请注意行内和行末可能有多余的空格,你的程序需要能处理这些空格。
每个整数代表一个 ID 号。
Output
要求程序输出 1 行,含两个整数 mm nn,用空格分隔。
其中,mm 表示断号 ID,nn 表示重号 ID
Examples
input
Copy
2 5 6 8 11 9 10 12 9
output
Copy
7 9
input
Copy
6 164 178 108 109 180 155 141 159 104 182 179 118 137 184 115 124 125 129 168 196 172 189 127 107 112 192 103 131 133 169 158 128 102 110 148 139 157 140 195 197 185 152 135 106 123 173 122 136 174 191 145 116 151 143 175 120 161 134 162 190 149 138 142 146 199 126 165 156 153 193 144 166 170 121 171 132 101 194 187 188 113 130 176 154 177 120 117 150 114 183 186 181 100 163 160 167 147 198 111 119
output
Copy
105 120
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
嘟嘟嘟嘟嘟嘟
喇叭响
我是汽车小司机
我是小司机
我为祖国运输忙
运输忙
这是儿歌"快乐的小司机"。话说现在当司机光有红心不行,还要多拉快跑。多拉不是超载,是要让所载货物价值最大,特别是在当前油价日新月异的时候。司机所拉货物为散货,如大米、面粉、沙石、泥土......
现在知道了汽车核载重量为 ww,可供选择的物品的数量 nn。每个物品的重量为 gigi,价值为 pipi。求汽车可装载的最大价值。
(n<10000,w<10000,0 Input 输入第一行为由空格分开的两个整数 nn, ww 第二行到第 n+1n+1 行,每行有两个整数,由空格分开,分别表示 gigi 和 pipi Output 最大价值(保留一位小数) Example input Copy output Copy Note 先装第 5 号物品,得价值 35,占用重量 7 再装第 4 号物品,得价值 36.346,占用重量 29 最后保留一位小数,得 71.3 一个名叫是 PigHeadThree 的研究组织设计了一台实验用的计算机,命名为 PpMm。PpMm 只能执行简单的六种命令 A,B,C,D,E,F;只有二个内存 M1,M2;三个寄存器 R1,R2,R3。六种命令的含义如下: 命令 A:将内存 M1 的数据装到寄存器 R1 中; 命令 B:将内存 M2 的数据装到寄存器 R2 中; 命令 C:将寄存器 R3 的数据装到内存 M1 中; 命令 D:将寄存器 R3 的数据装到内存 M2 中; 命令 E:将寄存器 R1 中的数据和寄存器 R2 中的数据相加,结果放到寄存器 R3 中; 命令 F:将寄存器 R1 中的数据和寄存器 R2 中的数据相减,结果放到寄存器 R3 中。 你的任务是:设计一个程序模拟 PpMm 的运行。 Input 有若干组,每组有 2 行,第一行是 2 个整数,分别表示 M1 和 M2 中的初始内容;第二行是一串长度不超过 200 的由大写字母 A 到 F 组成的命令串,命令串的含义如上所述。 Output 对应每一组的输入,输出只有一行,二个整数,分别表示 M1,M2 的内容;其中 M1 和 M2 之间用逗号隔开。 其他说明:R1,R2,R3 的初始值为 0,所有中间结果都在 −231−231 和 231231 之间。 Example input Copy output Copy You have a Petri dish with bacteria and you are preparing to dive into the harsh micro-world. But, unfortunately, you don't have any microscope nearby, so you can't watch them. You know that you have nn bacteria in the Petri dish and size of the ii-th bacteria is aiai. Also you know intergalactic positive integer constant KK. The ii-th bacteria can swallow the jj-th bacteria if and only if ai>ajai>aj and ai≤aj+Kai≤aj+K. The jj-th bacteria disappear, but the ii-th bacteria doesn't change its size. The bacteria can perform multiple swallows. On each swallow operation any bacteria ii can swallow any bacteria jjif ai>ajai>aj and ai≤aj+Kai≤aj+K. The swallow operations go one after another. For example, the sequence of bacteria sizes a=[101,53,42,102,101,55,54]a=[101,53,42,102,101,55,54] and K=1K=1. The one of possible sequences of swallows is: [101,53,42,102,101––––,55,54][101,53,42,102,101_,55,54] →→ [101,53–––,42,102,55,54][101,53_,42,102,55,54] →→ [101––––,42,102,55,54][101_,42,102,55,54] →→ [42,102,55,54–––][42,102,55,54_] →→ [42,102,55][42,102,55]. In total there are 33 bacteria remained in the Petri dish. Since you don't have a microscope, you can only guess, what the minimal possible number of bacteria can remain in your Petri dish when you finally will find any microscope. Input The first line contains two space separated positive integers nn and KK (1≤n≤2⋅1051≤n≤2⋅105, 1≤K≤1061≤K≤106) — number of bacteria and intergalactic constant KK. The second line contains nn space separated integers a1,a2,…,ana1,a2,…,an (1≤ai≤1061≤ai≤106) — sizes of bacteria you have. Output Print the only integer — minimal possible number of bacteria can remain. Examples input Copy output Copy input Copy output Copy input Copy output Copy Note The first example is clarified in the problem statement. In the second example an optimal possible sequence of swallows is: [20,15,10,15,20–––,25][20,15,10,15,20_,25] →→ [20,15,10,15–––,25][20,15,10,15_,25] →→ [20,15,10–––,25][20,15,10_,25] →→ [20,15–––,25][20,15_,25] →→ [20–––,25][20_,25] →→ [25][25]. In the third example no bacteria can swallow any other bacteria. As the new term comes, the Ignatius Train Station is very busy nowadays. A lot of student want to get back to school by train(because the trains in the Ignatius Train Station is the fastest all over the world ^v^). But here comes a problem, there is only one railway where all the trains stop. So all the trains come in from one side and get out from the other side. For this problem, if train A gets into the railway first, and then train B gets into the railway before train A leaves, train A can't leave until train B leaves. The pictures below figure out the problem. Now the problem for you is, there are at most 9 trains in the station, all the trains has an ID(numbered from 1 to n), the trains get into the railway in an order O1, your task is to determine whether the trains can get out in an order O2. Input Each test case consists of an integer, the number of trains, and two strings, the order of the trains come in:O1, and the order of the trains leave:O2. The input is terminated by the end of file. More details in the Sample Input. Output The output contains a string "No." if you can't exchange O2 to O1, or you should output a line contains "Yes.", and then output your way in exchanging the order(you should output "in" for a train getting into the railway, and "out" for a train getting out of the railway). Print a line contains "FINISH" after each test case. More details in the Sample Output. Examples input Copy output Copy input Copy output Copy Note For the first Sample Input, we let train 1 get in, then train 2 and train 3. So now train 3 is at the top of the railway, so train 3 can leave first, then train 2 and train 1. In the second Sample input, we should let train 3 leave first, so we have to let train 1 get in, then train 2 and train 3. Now we can let train 3 leave. But after that we can't let train 1 leave before train 2, because train 2 is at the top of the railway at the moment. So we output "No.". 如图所示的螺旋折线经过平面上所有整点恰好一次。 对于整点 (X,Y)(X,Y),我们定义它到原点的距离 dis(X,Y)dis(X,Y) 是从原点到 (X,Y)(X,Y) 的螺旋折线段的长度。 例如 dis(0,1)=3dis(0,1)=3, dis(−2,−1)=9dis(−2,−1)=9 给出整点坐标 (X,Y)(X,Y),你能计算出 dis(X,Y)dis(X,Y) 吗? Input 输入包含两个整数 XX 和 YY, (−1000000000<=X,Y<=1000000000)(−1000000000<=X,Y<=1000000000) Output 输出 dis(X,Y)dis(X,Y) Example input Copy output Copy There are nn segments [li,ri][li,ri] for 1≤i≤n1≤i≤n. You should divide all segments into two non-empty groups in such way that there is no pair of segments from different groups which have at least one common point, or say that it's impossible to do it. Each segment should belong to exactly one group. To optimize testing process you will be given multitest. Input The first line contains one integer TT (1≤T≤500001≤T≤50000) — the number of queries. Each query contains description of the set of segments. Queries are independent. First line of each query contains single integer nn (2≤n≤1052≤n≤105) — number of segments. It is guaranteed that ∑n∑n over all queries does not exceed 105105. The next nn lines contains two integers lili, riri per line (1≤li≤ri≤2⋅1051≤li≤ri≤2⋅105) — the ii-th segment. Output For each query print nn integers t1,t2,…,tnt1,t2,…,tn (ti∈{1,2}ti∈{1,2}) — for each segment (in the same order as in the input) titi equals 11 if the ii-th segment will belongs to the first group and 22 otherwise. If there are multiple answers, you can print any of them. If there is no answer, print −1−1. Example input Copy output Copy Note In the first query the first and the second segments should be in different groups, but exact numbers don't matter. In the second query the third segment intersects with the first and the second segments, so they should be in the same group, but then the other group becomes empty, so answer is −1−1. In the third query we can distribute segments in any way that makes groups non-empty, so any answer of 66 possible is correct.5 36
99 87
68 36
79 43
75 94
7 35
71.3
#include
最简单的计算机
100 288
ABECED
388,388
#include
Micro-World
7 1
101 53 42 102 101 55 54
3
6 5
20 15 10 15 20 25
1
7 1000000
1 1 1 1 1 1 1
7
#include
Train Problem I
3 123 321
Yes.
in
in
in
out
out
out
FINISH
3 123 312
No.
FINISH
#include
螺旋折线
0 1
3
#include
Division and Union
3
2
5 5
2 3
3
3 5
2 3
2 3
3
3 3
4 4
5 5
2 1
-1
1 1 2
#include