Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <bits/stdc++.h>
- using namespace std;
- const int N = 200009;
- int a[N];
- int main() {
- ios_base::sync_with_stdio(false);
- cin.tie(nullptr);
- cout.tie(nullptr);
- // freopen("/home/hamoudi/Coding/run.in", "r", stdin);
- int tt = 1;
- // cin >> tt;
- while (tt--) {
- // For a non-degenerate triangle, its sides should follow these constraints,
- // A + B > C and
- // B + C > A and
- // C + A > B
- // where A, B and C are length of sides of the triangle.
- int n;
- cin >> n;
- for (int i = 0; i < n; ++i) {
- cin >> a[i];
- }
- sort(a, a + n);
- long long len = a[0] + a[1] - 1;
- // check if this len will be valid to be third segment or not
- if (len + a[0] > a[n - 1]) {
- cout << "YES\n" << len;
- } else {
- cout << "NO\n";
- }
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement