# 2018-BNUZ-ACM-GDCPC选拔赛 【补题】

#### standard output

While Mahmoud and Ehab were practicing for IOI, they found a problem which name was Longest common subsequence. They solved it, and then Ehab challenged Mahmoud with another problem.

Given two strings a and b, find the length of their longest uncommon subsequence, which is the longest string that is a subsequence of one of them and not a subsequence of the other.

A subsequence of some string is a sequence of characters that appears in the same order in the string, The appearances don't have to be consecutive, for example, strings "ac", "bc", "abc" and "a" are subsequences of string "abc" while strings "abbc" and "acb" are not. The empty string is a subsequence of any string. Any string is a subsequence of itself.

Input

The first line contains string a, and the second line — string b. Both of these strings are non-empty and consist of lowercase letters of English alphabet. The length of each string is not bigger than 105 characters.

Output

If there's no uncommon subsequence, print "-1". Otherwise print the length of the longest uncommon subsequence of a and b.

Examples
Input
Copy
abcd
defgh

Output
Copy
5

Input
Copy
a
a

Output
Copy
-1

Note

In the first example: you can choose "defgh" from string b as it is the longest subsequence of string b that doesn't appear as a subsequence of string a.

## 这个题着实把我坑了一把，读题读出来是找最长不同子序列，然后wa了几发后，在读样例感觉并不是，结果开始各种尝试，最后也没过，后来才明白这个题就是如果两个字符串不同，就输出最长的字符串长度，如果相同，就输出-1，真的想吐血，被这种水题卡真的难受的要死。

#include<bits/stdc++.h>
using namespace std;
int main() {
int t,alen,blen,j =0,num;
char a[100005],b[100005];
scanf("%s",&a);
getchar();
scanf("%s",&b);
alen = strlen(a);
blen = strlen(b);
for(int i = 0; i < alen; i++) {
if(a[i] != b[i]) {
j = 1;
}
}
for(int i = 0; i < blen; i++) {
if(a[i] != b[i]) {
j = 1;
}
}
if(j) {
if(alen > blen) {
printf("%d\n",alen);
} else {
printf("%d\n",blen);
}
} else {
printf("%d\n",-1);
}

}

#### standard output

Mahmoud has n line segments, the i-th of them has length ai. Ehab challenged him to use exactly 3 line segments to form a non-degenerate triangle. Mahmoud doesn't accept challenges unless he is sure he can win, so he asked you to tell him if he should accept the challenge. Given the lengths of the line segments, check if he can choose exactly 3 of them to form a non-degenerate triangle.

Mahmoud should use exactly 3 line segments, he can't concatenate two line segments or change any length. A non-degenerate triangle is a triangle with positive area.

Input

The first line contains single integer n (3 ≤ n ≤ 105) — the number of line segments Mahmoud has.

The second line contains n integers a1, a2, ..., an (1 ≤ ai ≤ 109) — the lengths of line segments Mahmoud has.

Output

In the only line print "YES" if he can choose exactly three line segments and form a non-degenerate triangle with them, and "NO" otherwise.

Examples
Input
Copy
5
1 5 3 2 4

Output
Copy
YES

Input
Copy
3
4 1 2

Output
Copy
NO

Note

For the first example, he can use line segments with lengths 2, 4 and 5 to form a non-degenerate triangle.

### 然后是这个题，给你一堆边，从中选三个能否组成三角形，能就是yes，否则是no，这个一看就是水题，上来第一道就尝试这个，结果脑袋就不转了，就想着暴力暴力，三个for怎么想都是tle，然后又想复杂了，想着先排序，然后第一个第二个相加，在二分查找找到比他们大的值，然后再判断是否三角形，这样更写不出来。。真的不知道怎么了，反正脑子就是一片空白，除了暴力，什么都想不到，然后优化又没有想法，最后无奈放弃。。结束看了题解后才发现根本没有那么复杂，甚至都不用挨个判断两边之和大于第三边，直接排序然后遍历用两个小的边相加大于最大边就有符合条件的直接yes，否则就no，真的没有那么麻烦，但是自己就是死活想不到，怀疑自己需要学习小学数学了，唉，继续努力，下次再有机会，一定不能错过。

#include<bits/stdc++.h>
using namespace std;
int main() {
int t,ans,n,num[100005],p,l;
p = 0;
l = 1;
scanf("%d",&t);
for(int i = 0; i < t; i++) {
scanf("%d",&num[i]);
}
sort(num,num+t);
for(int i =0; i < t-2;i++){
if(num[i]  + num[i+1] >num[i+2]){
p = 1;
}
}
if(p){
printf("YES\n");
}else{
printf("NO\n");
}
}

• 广告
• 抄袭
• 版权
• 政治
• 色情
• 无意义
• 其他

120