February Cook-Off 2022 Division 4

February Cook-Off 2022 Division 4


February Cook-Off 2022 Division 4


Complete the credits

In Uttu's college, a semester is said to be a:

  • Overload semester if the number of credits taken >65.
  • Underload semester if the number of credits taken <35.
  • Normal semester otherwise

Given the number of credits X taken by Uttu, determine whether the semester is OverloadUnderload or Normal.

Input Format

  • The first line will contain T - the number of test cases. Then the test cases follow.
  • The first and only of each test case contains a single integer X - the number of credits taken by Uttu.

You may print each character of OverloadUnderload and Normal in uppercase or lowercase (for example, ovErLoAdoVERlOADOVERLOAD will be considered identical).

Output Format

For each test case, output OverloadUnderload or Normal depending upon the number of credits taken by Uttu.

Constraints

  • 1T100
  • 1X100

Sample Input 1 

4
65
80
23
58

Sample Output 1 

Normal
Overload
Underload
Normal


#include <iostream>

using namespace std;


int main() {

    

    int test;

    

    cin>>test;

    

    while(test--)

   { int c;

     cin>>c;

     

     if(c>65) cout<<"Overload"<<endl;

     

    else if(c<35) cout<<"Underload"<<endl;

    

else cout<<"Normal"<<endl;

       

   }

   

return 0;

}


Guess the bottom face


It is known that in regular dice, the sum of opposite faces is 7.

A regular dice is rolled and you are given the value X showing on the top face. Determine the value on the bottom face.

Input Format

  • The first line will contain T - the number of test cases. Then the test cases follow.
  • The first and only of each test case contains a single integer X - the value on the top face.

Output Format

For each test case, output the value on the bottom face.

Constraints

  • 1T6
  • 1X6

Sample Input 1 

3
3
1
6

Sample Output 1 

4
6
1

Explanation

Test case-1: The value on the top face is 3. Therefore, the value on the bottom face is 4 because 3+4=7.

Test case-2: The value on the top face is 1. Therefore, the value on the bottom face is 6 because 1+6=7.

Test case-3: The value on the top face is 6. Therefore, the value on the bottom face is 1 because 6+1=7.


#include <iostream>

using namespace std;


int main() {

    

int t,s;

cin>>t;

while(t--){

    

    cin>>s;

    

    cout<<7-s<<endl;

}

return 0;

}



Peaceful Party 


The mayor of your city has decided to throw a party to gather the favour of his people in different regions of the city.

There are 3 distinct regions in the city namely ABC comprising of PAPB and PC number of people respectively.

However, the mayor knows that people of the region B are in conflict with people of regions A and C. So, there will be a conflict if people from region B are present at the party along with people from region A or C.

The mayor wants to invite as many people as possible and also avoid any conflicts. Help him invite maximum number of people to the party.

Input Format

  • The first line contains a single integer T - the number of test cases. Then the test cases follow.
  • The first line of each test case contains three integers PAPB and PC - number of people living in regions AB and C respectively.

Output Format

For each test case, output the maximum number of people that can be invited to the party.

Constraints

  • 1T1000
  • 1PA,PB,PC1000

Sample Input 1 

3
2 3 4
1 5 2
8 8 8

Sample Output 1 

6
5
16

Explanation

Test case-1: Mayor can invite all the people from region A and C. So the maximum number of people invited is 6.

Test case-2: Mayor can invite all the people from region B. So the maximum number of people invited is 5.


#include <iostream>
using namespace std;

int main() {
    
int t;
int a,b,c;
cin>>t;
while(t--){ cin>>a>>b>>c;
    if(b>a+c){
    cout<<b<<endl;}
    else {cout<<a+c<<endl;}
}
return 0;
}


Lazy Salesman


Ved is a salesman. He needs to earn at least W rupees in N days for his livelihood. However, on a given day i (1iN), he can only earn Ai rupees by working on that day.

Ved, being a lazy salesman, wants to take as many holidays as possible. It is known that on a holiday, Ved does not work and thus does not earn anything. Help maximize the number of days on which Ved can take a holiday.

It is guaranteed that Ved can always earn at least W rupees by working on all days.

Input Format

  • The first line contains a single integer T - the number of test cases. Then the test cases follow.
  • The first line of each test case contains two integers N and W - the size of the array A and the money Ved has to earn in those N days.
  • The second line of each test case contains N space-separated integers A1,A2,,AN denoting the money which Ved can earn on each day.

Output Format

For each test case, output the maximum number of holidays Ved can take.

Constraints

  • 1T100
  • 1W10000
  • 1N100
  • 1Ai100
  • It is guaranteed that Ved can always earn at least W rupees by working on all days.

Sample Input 1 

3
5 10
3 2 6 1 3
4 15
3 2 4 6
6 8
9 12 6 5 2 2

Sample Output 1 

2
0
5

Explanation

Test case-1: Ved can work on 2-nd, 3-rd and 5-th day earning 2+6+3=11 rupees W rupees. Thus he can take 2 holidays on the 1-st and the 4-th day.

Test case-2: Ved has to work on all days to earn W rupees. Thus he can not take any holidays.

Test case-3: Ved can work on 2-nd day earning 12 rupees W rupees. Thus he can take holiday on the remaining days.


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

int main() {
    
int t;
int a,b,d,c[101];
//input
cin>>t;
while(t--){ 
    
    cin>>a>>b;
    
    
    for(int i=0;i<a;i++) cin>>c[i]; 
    d=a;
    
    
        sort(c, c + a, greater<int>());
        
        
    for(int i=0;i<a;i++)
    {
        b-=c[i]; d--;
      if(b>0) continue;
      else break;
    }
    
    
        cout<<d<<endl;
}
return 0;
}


For More Check here : https://www.codechef.com/COOK138D

Complete the credits
Guess the bottom face 
Peaceful Party 
Lazy Salesman HOLIDAYS 
Prefix Permutation PREFPERM 
Perfect Permutation PERFPERM 
PerMEXuation PERMEX