Advertisement
Hamoudi30

Problem A

May 14th, 2022
100
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.91 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3. const int N = 200009;
  4. int a[N];
  5. int main() {
  6.     ios_base::sync_with_stdio(false);
  7.     cin.tie(nullptr);
  8.     cout.tie(nullptr);
  9. //    freopen("/home/hamoudi/Coding/run.in", "r", stdin);
  10.     int tt = 1;
  11. //    cin >> tt;
  12.     while (tt--) {
  13. //        For a non-degenerate triangle, its sides should follow these constraints,
  14. //        A + B > C    and
  15. //        B + C > A    and
  16. //        C + A > B
  17. //        where A, B and C are length of sides of the triangle.
  18.         int n;
  19.         cin >> n;
  20.         for (int i = 0; i < n; ++i) {
  21.             cin >> a[i];
  22.         }
  23.         sort(a, a + n);
  24.         long long len = a[0] + a[1] - 1;
  25. //        check if this len will be valid to be third segment or not
  26.         if (len + a[0] > a[n - 1]) {
  27.             cout << "YES\n" << len;
  28.         } else {
  29.             cout << "NO\n";
  30.         }
  31.     }
  32.     return 0;
  33. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement