TRICHECK - Editorial

PROBLEM LINK:

Practice
Contest: Division 1
Contest: Division 2
Contest: Division 3
Contest: Division 4

Author: raysh07
Tester: sushil2006
Editorialist: iceknight1093

DIFFICULTY:

Cakewalk

PREREQUISITES:

None

PROBLEM:

Given three integers A, B, and C, check if they can form the sides of a non-degenerate triangle.

EXPLANATION:

Simply implement what the statement says: check if each of the three lengths is strictly smaller than the sum of the other two.

A simple way to implement this check without casework is to check if

2\cdot\max(A, B, C) < A + B + C

This is equivalent to performing all three checks, because

  • A \lt B+C \iff 2A \lt A+B+C
  • B\lt A+C \iff 2B \lt A+B+C
  • C\lt A+B \iff 2C \lt A+B+C

So if the maximum of A,B,C satisfies the inequality, all three of them will.

TIME COMPLEXITY:

\mathcal{O}(1) per testcase.

CODE:

Editorialist's code (PyPy3)
a, b, c = map(int, input().split())
print('Yes' if 2*max(a, b, c) < a + b + c else 'No')
1 Like