PCJ18A - Editorial

PROBLEM LINK:

Practice
Contest

Author: Madhav Sainanee
Tester: Prakhar Gupta
Editorialist: Prakhar Gupta

DIFFICULTY:

CAKEWALK

PREREQUISITES:

None

PROBLEM:

Given N dishes, find out if there is atleast one dish with amount of secret ingredient \geq X

EXPLANATION:

We go over the amount of secret ingredient in all the N dishes. If we find a dish which has amount of secret ingredient more than or equal to X, we print ‘YES’.

One mistake participants did was break from the input loop once they found an A_i \geq X. This led to the remaining input of the current test case to be transferred to the next test case, leading to a Wrong Answer, or sometimes a Runtime Error verdict.

Complexity: The time complexity is O(N) per test case.

AUTHOR’S SOLUTION:

Author’s solution can be found here.

2 Likes
#include <iostream>
using namespace std;
using ll = long long;

int main() {
	int t;
	cin >> t;
	while (t--) {
		int n, x;
		cin >> n >> x;
		int ans[1001];
		for (int i = 0; i < n; i++) {
			cin >> ans[i];
		}
		bool an = false;
		for (int i = 0; i < n; i++) {
			if (ans[i] >= x) {
				an = true;
			}
		}
		if (an) {
			cout << "YES" << endl;
		}
		else {
			cout << "NO" << endl;
		}
	}
}