April Lunchtime 2022 Division 4(Rated)

 April Lunchtime 2022 Division 4(Rated)








Lunchtime (Link)


Chef has his lunch only between 1 pm and 4 pm (both inclusive).

Given that the current time is X pm, find out whether it is lunchtime for Chef.

Input Format
The first line of input will contain a single integer T, the number of test cases. Then the test cases follow.
Each test case contains a single line of input, containing one integer X.
Output Format
For each test case, print in a single line YES if it is lunchtime for Chef. Otherwise, print NO.

You may print each character of the string in either uppercase or lowercase (for example, the strings YeS, yEs, yes and YES will all be treated as identical).

Constraints
1≤T≤12
1≤X≤12

Sample Input 1 
3
1
7
3

Sample Output 1 
YES
NO
YES

Explanation
Test case 1: Lunchtime is between 1 pm and 4 pm (both inclusive). Since 1 pm lies within lunchtime, the answer is YES.

Test case 2: Lunchtime is between 1 pm and 4 pm (both inclusive). Since 7 pm lies outside lunchtime, the answer is NO.

Test case 3: Lunchtime is between 1 pm and 4 pm (both inclusive). Since 3 pm lies within lunchtime, the answer is YES.

Solution : 

#include <iostream>
using namespace std;

int main() {
int test;
int a;
cin>>test;
while(test--){

    cin>>a;
    if(a >=1 && a <=4)
cout<<"YES"<<endl;
else cout<<"NO"<<endl;
}
return 0;
}



Mario and Transformation (Link)



Mario transforms each time he eats a mushroom as follows:

If he is currently small, he turns normal.
If he is currently normal, he turns huge.
If he is currently huge, he turns small.
Given that Mario was initially normal, find his size after eating X mushrooms.

Input Format
The first line of input will contain one integer T, the number of test cases. Then the test cases follow.
Each test case contains a single line of input, containing one integer X.
Output Format
For each test case, output in a single line Mario's size after eating X mushrooms.

Print:

NORMAL, if his final size is normal.
HUGE, if his final size is huge.
SMALL, if his final size is small.
You may print each character of the answer in either uppercase or lowercase (for example, the strings Huge, hUgE, huge and HUGE will all be treated as identical).

Constraints
1≤T≤100
1≤X≤100
Sample Input 1 
3
2
4
12


Sample Output 1 
SMALL
HUGE
NORMAL


Explanation
Test case 1: Mario's initial size is normal. On eating the first mushroom, he turns huge. On eating the second mushroom, he turns small.

Test case 2: Mario's initial size is normal. On eating the first mushroom, he turns huge. On eating the second mushroom, he turns small. On eating the third mushroom, he turns normal. On eating the fourth mushroom, he turns huge.


Solution :
#include <iostream>
using namespace std;

int main() {
int test_case;
int sizee;
cin>>test_case;
while(test_case--)
{
    cin>>sizee;
    if(sizee%3 == 0) {
cout<<"NORMAL"<<endl;
}
    else if(sizee%3 == 1) {
cout<<"HUGE"<<endl;
}
    else {
cout<<"SMALL"<<endl;
}
}
return 0;
}


Mario and Bullet (Link)


Mario's bullet moves at X pixels per frame. He wishes to shoot a goomba standing Y pixels away from him. The goomba does not move.

Find the minimum time (in seconds) after which Mario should shoot the bullet, such that it hits the goomba after at least Z seconds from now.

Input Format
The first line of input will contain an integer T, the number of test cases. Then the test cases follow.
Each test case consists of a single line of input, containing three space-separated integers X,Y, and Z.
Output Format
For each test case, output in a single line the minimum time (in seconds) after which Mario should shoot the bullet, such that it hits the goomba after at least Z seconds from now.

Constraints
1≤T≤100
1≤X,Y,Z≤100
X divides Y


Sample Input 1 
3
3 3 5
2 4 1
3 12 8


Sample Output 1 
4
0
4


Explanation
Test case 1: The speed of the bullet is 3 pixels per frame and the goomba is 3 pixels away from Mario. Thus, it would take 1 second for the bullet to reach the goomba. Mario wants the bullet to reach goomba after at least 5 seconds. So, he should fire the bullet after 4 seconds.

Test case 2: The speed of the bullet is 2 pixels per frame and the goomba is 4 pixels away from Mario. Thus, it would take 2 seconds for the bullet to reach the goomba. Mario wants the bullet to reach the goomba after at least 1 second. So, he should fire the bullet after 0 seconds. Note that, this is the minimum time after which he can shoot a bullet.

Test case 3: The speed of the bullet is 3 pixels per frame and the goomba is 12 pixels away from Mario. Thus, it would take 4 seconds for the bullet to reach the goomba. Mario wants the bullet to reach goomba after at least 8 seconds. So, he should fire the bullet after 4 seconds.


Solution :

#include <iostream>
using namespace std;

int main() {
int testcase;
int x;
int y;
int z;
cin>>testcase;
while(testcase--){
    cin>>x;
    cin>>y;
    cin>>z;
    
    if(y/x<=z) {
        
        cout<< z-(y/x);
        cout<<endl;
        
    }
    else {
        cout<<0;
    cout<<endl;
        
    }
}
return 0;
}



Pair Pain (Link)


You are given an array A containing N positive integers. Find the number of pairs (i,j) such that 1≤i<j≤N and:
Ai+Aj≥Ai⋅Aj
Input Format
The first line contains an integer T denoting the number of test cases. The T test cases then follow.
The first line of each test case contains an integer N.
The second line of each test case contains N space-separated integers A1,A2,…,AN.
Output Format
For each test case, output on a new line the required answer.

Constraints
1≤T≤1000
2≤N≤2⋅105
1≤Ai≤106
Sum of N over all cases won't exceed 2⋅105
Sample Input 1 
2
3
1 3 4
5
2 3 4 5 6
Sample Output 1 
2
0
Explanation
Test case 1: The two pairs are (1,2) and (1,3), because:

A1+A2=4>3=A1⋅A2
A1+A3=5>4=A1⋅A3
Test case 2: No pairs satisfy the condition.

Solution :

#include <iostream>
#define ll long long int
using namespace std;

int main() {
ll t;
cin>>t;
while(t--){
    ll n;
    cin>>n;
    ll a[n];
    ll count=0;
    ll ans=0;
    for(ll i=0;i<n;i++){
        cin>>a[i];
        
        if(a[i]==1){
            ans++;
        }
        if(a[i]==2){
            count++;
        }
    }
   
    cout<<count*(count-1)/2+ans*(ans-1)/2+ans*(n-ans)<<endl;
    
  
   
    
}
return 0;
}