PROBLEM LINK:
Practice
Contest: Division 1
Contest: Division 2
Contest: Division 3
Contest: Division 4
Author: raysh07
Tester: iceknight1093
Editorialist: iceknight1093
DIFFICULTY:
Cakewalk
PREREQUISITES:
None
PROBLEM:
Chef wrote three exams, and scored X, Y, Z marks in them out of 100.
He needs to score at least 50 in at least two exams to pass.
Did Chef pass?
EXPLANATION:
It’s enough to simply implement and check exactly what the statement asks for.
Count the number of exams Chef received a score of \ge 50 in.
That is, initialize a variable C = 0.
Then, for each of X, Y, Z, if the value is \ge 50, add 1 to C.
C represents the number of exams Chef has a score of at least 50 in.
In the end, if C \ge 2 the answer is Yes, otherwise the answer is No.
TIME COMPLEXITY:
\mathcal{O}(1) per testcase.
CODE:
Editorialist's code (C++)
#include <bits/stdc++.h>
using namespace std;
int main() {
int t; cin >> t;
while (t--) {
int x, y, z;
cin >> x >> y >> z;
int pass = 0;
if (x >= 50) pass += 1;
if (y >= 50) pass += 1;
if (z >= 50) pass += 1;
if (pass >= 2) cout << "Yes\n";
else cout << "No\n";
}
}