problem from contest
Zaikia and sticks Problem Code: CKOJ20A
Zaikia has sticks of distinct positive lengths . For no good reason at all, he wants to know if there is a triplet of sticks which when connected end-to-end will form a non-trivial triangle. Here non-trivial refers to a triangle with positive area.
Help Zaikia know if such a triplet exists or not. If such a triplet exists, help him find the lexicographically largest applicable triplet.
Input
- The first line contains an integer .
- The second line contains space-seperated integers .
Output
- In the first line print
YESif a triplet exists orNOif it doesn't. - If such a triplet exists, then in the second line print the lexicographically largest applicable triplet.
Constraints
- for each valid
Sample Input 1
5
4 2 10 3 5
Sample Output 1
YES
5 4 3
Explanation 1
There are three unordered triplets of sticks which can be used to create a triangle:
Arranging them in lexicographically largest fashion
Here is the lexicographically largest so it is the triplet which dristiron wants
Sample Input 2
5
1 2 4 8 16
Sample Output 2
NO
Explanation 2
There are no triplets of sticks here that can be used to create a triangle.
1
#include <bits/stdc++.h>
using namespace std;
const int N = 200010;
int n, a[N];
int main() {
cin >> n;
for (int i = 1; i <= n; ++i) scanf("%d", a + i);
sort(a + 1, a + n + 1);
for (int i = n; i >= 3; --i) {
if (a[i - 1] + a[i - 2] > a[i]) {
puts("YES");
printf("%d %d %d\n", a[i], a[i - 1], a[i - 2]);
return 0;
}
}
puts("NO");
return 0;
}
2.
Even-tual Reduction Problem Code: EVENTUAL
Read problems statements in Hindi, Mandarin Chinese, Russian, Vietnamese, and Bengali as well.
You are given a string
before and after the erased substring are concatenated and the next operation is performed on this shorter string.)
For example, from the string "acabbad", we can erase the highlighted substring "abba", since each character occurs an even number of times in this substring. After this operation, the remaining string is "acd".
Is it possible to erase the whole string using one or more operations?
Note: A string
is a substring of a string if can be obtained fromby deleting several (possibly none or all) characters from the beginning and several (possibly none or all) characters from the end.
Input
- The first line of the input contains a single integer
- .
Output
For each test case, print a single line containing the string "YES" if it is possible to erase the whole string or "NO" otherwise (without quotes).
Constraints
- contains only lowercase English letters
Example Input
4
6
cabbac
7
acabbad
18
fbedfcbdaebaaceeba
21
yourcrushlovesyouback
Example Output
YES
NO
YES
NO
Explanation
Example case 1: We can perform two operations: erase the substring "abba", which leaves us with the string "cc", and then erase "cc".
1.
2.
Comments
Post a Comment