PROBLEM LINK:
Practice
Contest: Division 1
Contest: Division 2
Contest: Division 3
Contest: Division 4
Author: Hriday
Testers: Abhinav Sharma, Venkata Nikhil Medam
Editorialist: Nishank Suresh
DIFFICULTY:
447
PREREQUISITES:
None
PROBLEM:
There are two TVs: the first costs A rupees and has a discount of C rupees, while the second costs B rupees and has a discount of D rupees. Which one is cheaper?
EXPLANATION:
This is a simple application of if-conditions. The overall cost of the first TV is A - C rupees, while that of the second TV is B - D rupees. Compute these two values, then use if-else conditions to compare them and find out which one is less, or if they are equal.
TIME COMPLEXITY:
\mathcal{O}(1) per test case.
CODE:
Tester (C++)
// Tester: Nikhil_Medam
#include <bits/stdc++.h>
using namespace std;
#define endl "\n"
int t, a, b, c, d;
int32_t main() {
cin >> t;
while(t--) {
cin >> a >> b >> c >> d;
if(a - c < b - d) {
cout << "First" << endl;
}
else if(a - c > b - d) {
cout << "Second" << endl;
}
else {
cout << "Any" << endl;
}
}
return 0;
}
Editorialist (Python)
for _ in range(int(input())):
a, b, c, d = map(int, input().split())
if a-c < b-d:
print('first')
else:
print('second' if a-c > b-d else 'any')