AITC2G15 - Editorial

PROBLEM LINK:

Practice

Contest Link:

Setter: Rahul Kumar

Tester: Rahul Kumar

Editorialist: Anushwar Sharma

DIFFICULTY:

Simple

PREREQUISITES:

Basic mathematics.

PROBLEM:

Chef and Bob have participated in a 100 meter race, organized in the Chefland. Before the race starts they both are said to stand on the start line. Chef runs at speed X and Bob runs at speed Y, both of them run at a constant speed (Their speed remains the same throughout the race). But after the race starts, Chef realizes that Bob was not at the start line. So after running for K distance Chef quits the race, and Bob reaches the end line t times after Chef quits.
Chef asks the organizing committee to check the distance by which Bob was away from the start line. You are one of the members of the organizing committee, so you have to find the distance by which Bob was away from the start line.

EXPLANATION

Given the speed of Chef and Bob, when Chef quits the race, we will calculate the time taken by him for covering the K distance. By this, we will get to know that how much time is spent by Bob till Chef quits. Time taken by Chef till he quits is K/X and time spent by Bob to reach end line after chef quits is given t. So the total time taken by Bob is K/X+t and to get the distance Bob has completed we use Distance= Speed * Time i.e, (K/X)*Y+t*Y.

SOLUTION:

Editorialist's Solution
#include<bits/stdc++.h>
using namespace std;
#define fio ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define vi vector<int>
#define w(x) int x; cin>>x; while(x--)
#define pb push_back 

int32_t main() {
    #ifndef ONLINE_JUDGE
        freopen("input.txt", "r", stdin);
        freopen("output.txt", "w", stdout);
    #endif   
    fio
    int T;
    cin>>T;
    while(T--)
    {
        long long int x,y,s,k,t;
        cin>>x>>y>>k>>t;
        s=(k*y)/x+t*y;
        cout<<abs(100-s)<<"\n";
    }
}

Note: If you are a beginner, don’t be scared of the few lines that have been written at the top. Just focus on the code starting from the variable declaration and if you don’t understand any shorthand terminology mentioned in the code, look at the top “#define”, where we have defined all the constants used in the code.

Feel free to share your approach, if you want to(even if it’s the same). Suggestions are welcomed as always had been. :slight_smile: