麻豆小视频在线观看_中文黄色一级片_久久久成人精品_成片免费观看视频大全_午夜精品久久久久久久99热浪潮_成人一区二区三区四区

首頁 > 學(xué)院 > 開發(fā)設(shè)計 > 正文

Codeforces Round #396 (Div. 2) A+B

2019-11-10 19:31:17
字體:
供稿:網(wǎng)友

A. Mahmoud and Longest Uncommon Subsequence

time limit per test:2 seconds

memory limit per test:256 megabytes

input:standard input

output: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 abcd defgh

Output 5

Input a a

Output -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. 題意:判斷兩個串的最長不公共子序列。 題解:-1或者最長的串。 代碼:

#include<bits/stdc++.h>using namespace std;string a,b;int main(){ cin>>a>>b; if(a!=b) cout<<max(a.length(),b.length()); else cout<<"-1"<<endl;}

B. Mahmoud and a Triangle

time limit per test:2 seconds

memory limit per test:256 megabytes

input:standard input

output: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 5 1 5 3 2 4

Output YES

Input 3 4 1 2

Output NO

Note

For the first example, he can use line segments with lengths 2, 4 and 5 to form a non-degenerate triangle. 題意:任取三個數(shù),問能否構(gòu)成不退化三角形。 題解:排個序判斷一下即可。 代碼:

#include <bits/stdc++.h>#define ll long longusing namespace std;const int N=1e5+10;ll a[N];int main(){ int n; cin>>n; for(int i=1; i<=n; i++) cin>>a[i]; sort(a+1,a+1+n); bool flag=false; for(int i=2; i<n; i++) { if(a[i]+a[i-1]>a[i+1]) flag=true; } if(flag) cout<<"YES"<<endl; else cout<<"NO"<<endl;}
上一篇:log4j日志記錄級別

下一篇:poj1517

發(fā)表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發(fā)表
主站蜘蛛池模板: videos真实高潮xxxx | 9999精品| 香蕉在线看| 精品爱爱 | 久久久久久麻豆 | 国产一级做a | 97中文字幕第一一一页 | 亚洲精品午夜国产va久久成人 | 萌白酱福利视频在线网站 | 国产亚洲欧美一区久久久在 | 免费看日韩片 | 国产一级中文字幕 | 国产一区二区三区四区在线 | 黄色片视频在线观看 | 国产免费www | 蜜桃免费在线 | 黄色18网站 | 国产精品成人一区二区三区电影毛片 | 久章草在线观看 | 久久亚洲精品久久国产一区二区 | 国产一区精品在线观看 | 久久久久久久九九九九 | 手机视频在线播放 | h视频在线免费观看 | 91九色视频观看 | 69性欧美高清影院 | 久久久久国产成人免费精品免费 | 欧美日韩国产成人在线观看 | 得得啪在线 | 一区二区三区视频在线观看 | 国产人成精品一区二区三 | 91精品国产99久久久久久红楼 | 国产精品久久久久久影视 | av电影在线免费观看 | 日本人乱人乱亲乱色视频观看 | 精品国产91久久久久久 | 久草在线视频福利 | 羞羞视频2023 | 男人午夜小视频 | 久久出精品| 成人在线视频一区 |