SGRFGL - Editorial

PROBLEM LINK:

Practice
Contest

Author: Shreyansh Narayan
Tester: Nikhil Sharma
Editorialist: Shreyansh Narayan

DIFFICULTY:

EASY

PREREQUISITES:

Basic knowledge of motion

PROBLEM:

At a given instant, you are at the p^{th} position. You will finish the race, once you go beyond the k^{th} position in t second(s). You have a certain velocity v (points/second). Find out if you will qualify for next round or not.

QUICK EXPLANATION:

Calculate if you can finish the race in the stipulated time, i.e. if you can reach beyond the final position on the X-axis.

EXPLANATION:

It is important to note that you are given your present position on the positive X-axis, not the initial position of the race.
So, based on your present position, the problem can be divided into three different cases.

Case 1
In the 1^{st} case, your present position is before the final position, i.e. p < k.
Hence, you still need to finish the race.
Again, depending on the velocity, we can have 2 cases.

  • If v <= 0, then it is impossible to reach the finish line.
  • If v > 0, then we need to check whether it is possible to reach in given time or not.
    So, we can use the following formula - displacement = velocity x time, to calculate the time taken and match it with the given time.

Case 2
There are again 2 sub-cases.

  • In the 1^{st} case, your present position is equal to the final position, i.e. p = p.
  • In the 2^{nd} case, your present position is after the final position, i.e. p > k.
    Hence, you have already finished the race.

In these situations, no matter what the velocity v and time t are, they don’t matter as you have already finished the race at the given instant of time.

TIME COMPLEXITY:

O(1)

SOLUTION:

Setter's & Editorialist's Solution
#include <bits/stdc++.h>
using namespace std;

int main() {
    long long k,p;
    cin >> k >> p;
    int v,t;
    cin >> v >> t;
    if(p<k) {
        if(v>0) {
            if(k-p<=v*t)
                cout << "Qualified\n";
            else
                cout << "Sorry\n";
        }
        else
            cout << "Sorry\n";
    }
    else
        cout << "Qualified\n";
    return 0;
}