PROBLEM LINK:
Contest Division 1
Contest Division 2
Contest Division 3
Contest Division 4
Setter: Hriday
Tester: Ashley Khoo, Nishant Shah
Editorialist: Prakhar Kochar
DIFFICULTY:
Cakewalk
PREREQUISITES:
None
PROBLEM:
There is a group of N friends who wish to enroll in a course together. The course has a maximum capacity of M students that can register for it. If there are K other students who have already enrolled in the course, determine if it will still be possible for all the N friends to do so or not.
EXPLANATION:
We are given that the course has a maximum capacity of M students. K students have already enrolled in the course; therefore , atmost M-K students can enroll in the course now. Since N friends wish to enroll in the course together, following 2 cases are possible :
- N \leq M-K; it will be possible for all the N friends to enroll in the course together, therefore the output will be YES.
- N \gt M-K; it will not be possible for all the N friends to enroll in the course together, therefore the output will be NO.
Examples
-
N = 5, M = 10, K = 5; Since 5 \leq 10 - 5, it is possible for all the 5 friends to enroll in the course together, therefore the output will be YES.
-
N = 10, M = 15, k = 10; Since 10 \gt 15-10, it is not possible for all the 10 friends to enroll in the course together, therefore the output will be NO.
TIME COMPLEXITY:
O(1) for each test case.
SOLUTION:
Tester-2's Solution
#include <bits/stdc++.h>
using namespace std;
/*
---------Input Checker(ref : https://pastebin.com/Vk8tczPu )-----------
*/
long long readInt(long long l, long long r, char endd)
{
long long x = 0;
int cnt = 0;
int fi = -1;
bool is_neg = false;
while (true)
{
char g = getchar();
if (g == '-')
{
assert(fi == -1);
is_neg = true;
continue;
}
if ('0' <= g && g <= '9')
{
x *= 10;
x += g - '0';
if (cnt == 0)
{
fi = g - '0';
}
cnt++;
assert(fi != 0 || cnt == 1);
assert(fi != 0 || is_neg == false);
assert(!(cnt > 19 || (cnt == 19 && fi > 1)));
}
else if (g == endd)
{
if (is_neg)
{
x = -x;
}
if (!(l <= x && x <= r))
{
cerr << l << ' ' << r << ' ' << x << '\n';
assert(1 == 0);
}
return x;
}
else
{
assert(false);
}
}
}
string readString(int l, int r, char endd)
{
string ret = "";
int cnt = 0;
while (true)
{
char g = getchar();
assert(g != -1);
if (g == endd)
{
break;
}
cnt++;
ret += g;
}
assert(l <= cnt && cnt <= r);
return ret;
}
long long readIntSp(long long l, long long r)
{
return readInt(l, r, ' ');
}
long long readIntLn(long long l, long long r)
{
return readInt(l, r, '\n');
}
string readStringLn(int l, int r)
{
return readString(l, r, '\n');
}
string readStringSp(int l, int r)
{
return readString(l, r, ' ');
}
/*
-------------Main code starts here------------------------
*/
// Note here all the constants from constraints
const int MAX_T = 1000;
const int MAX_N = 100;
void solve()
{
int n, m, k;
n = readIntSp(1, MAX_N);
m = readIntSp(n, MAX_N);
k = readIntLn(0, m);
if (n + k <= m)
{
cout << " \n YEs \n\n";
}
else
{
cout << " \n \n nO \n\n \n";
}
}
signed main()
{
int t;
t = readIntLn(1, MAX_T);
for (int i = 1; i <= t; i++)
{
solve();
}
// Make sure there are no extra characters at the end of input
assert(getchar() == -1);
cerr << "SUCCESS\n";
// Some important parameters which can help identify weakness in testdata
cerr << "Tests : " << t << '\n';
}
Editorialist's Solution
/*prakhar_87*/
#include <bits/stdc++.h>
using namespace std;
#define int long long int
#define inf INT_MAX
#define mod 998244353
void f() {
int n, m, k;
cin >> n >> m >> k;
if (n <= m - k) cout << "YES\n";
else cout << "NO\n";
}
int32_t main() {
ios::sync_with_stdio(0); cin.tie(0);
int t; cin >> t;
while (t--) f();
}