TR0001-EDITORIAL

PROBLEM LINK :

Practice
Contest

Author : sneha542
Tester : alkama_123
Editorialist : sneha542

DIFFICULTY :

Cakewalk

PREREQUISITES :

None

PROBLEM :

Recently, Sanskriti went to Goa with her friends. She has to follow certain budget. She had Rs. P at the start of the trip and has already spent Rs. Q on the trip. There are four kinds of rides she can enjoy, with prices Rs. W, X, Y, and Z. She wants to try each sport at least once.
If she can try all of them at least once output YES, otherwise output NO.

QUICK EXPLANATION :

First, sum the costs of all the rides and find the remaining money that Sanskriti has then compare both if the amount left is either equal or greater than the summing cost then print YES, otherwise print NO.

EXPLANATION :

→ Initially Sanskriti has P rupees. Out of that, Q rupees has already been spent. Now, the current amount he has will be P-Q rupees.

→ The minimum cost to try all the sports will be W+X+Y+Z rupees.

→ Therefore, if P-Q >= W+X+Y+Z, we output YES, else we output NO.

TIME COMPLEXITY :
O(1) for each test case.

SOLUTIONS :

Editorialist’s Solution

#include<bits/stdc++.h>
using namespace std;

int main()
{
int t;

cin>>t;



while(t--) {

    int p, q, w, x, y, z;

    cin>>p>>q>>w>>x>>y>>z;

    int d = p-q;

    if((w+x+y+z)<=d)

      cout<<"YES"<<endl;

    else

       cout<<"NO"<<endl;


 }

return 0;

}

Feel Free to share and discuss your approach here. :smiley: