PROBLEM LINK:
Setter: Daanish Mahajan
Tester: Rahul Dugar
Editorialist: Ishmeet Singh Saggu
DIFFICULTY:
Cakewalk
PREREQUISITES:
Maths
PROBLEM:
Given 3 numbers you have to tell whether it is possible to write any one of them as the sum of the other two integers
EXPLANATION:
If the largest number(out of the 3 numbers) is equal to the sum of the other 2 number then the answer is YES
else answer is NO
.
TIME COMPLEXITY:
- Time complexity per test case is O(1).
SOLUTIONS:
Editorialist's Solution
#include <bits/stdc++.h>
using namespace std;
void solve() {
int num[3];
cin >> num[0] >> num[1] >> num[2];
int largest = -1, sum = 0;
for(int i = 0; i < 3; i ++) {
largest = max(largest, num[i]);
sum += num[i];
}
if(sum-largest == largest) cout << "YES" << endl;
else cout << "NO" << endl;
}
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
int t;
cin >> t;
while(t --) {
solve();
}
return 0;
}