Counting Words
Harsh was recently gifted a book consisting of pages. Each page contains exactly words printed on it. As he was bored, he decided to count the number of words in the book.
Help Harsh find the total number of words in the book.
Input Format
- The first line of input will contain a single integer , denoting the number of test cases.
- Each test case consists of two space-separated integers on a single line, and — the number of pages and the number of words on each page, respectively.
Output Format
For each test case, output on a new line, the total number of words in the book.
Constraints
Sample Input 1
4
1 1
4 2
2 4
95 42
Sample Output 1
1
8
8
3990
Explanation
Test case : The book consists of only page, and each page has only word. Hence, the total number of words is .
Test case : The book consists of pages, and each page has words. Hence, the total number of words is .
Test case : The book consists of pages, and each page has words. Hence, the total number of words is .
Test case : The book consists of pages, and each page has words. Hence, the total number of words is .
Solution :
#include <iostream>
using namespace std;
int main() {
int t,a,b;
cin>>t;
while(t--){
cin>>a>>b;
cout<<a*b<<endl;
}
return 0;
}
For the upcoming semester, the admins of your university decided to keep a total of seats for the MATH-1
course. A student interest survey was conducted by the admins and it was found that students were interested in taking up the MATH-1
course.
Find the minimum number of extra seats that the admins need to add into the MATH-1
course to make sure that every student who is interested in taking the course would be able to do so.
Input Format
- The first line of input will contain a single integer , denoting the number of test cases.
- Each test case consists of two-space separated integers on a single line, and — the current number of seats up for enrolment and the number of students interested in taking up the course in the upcoming semester, respectively.
Output Format
For each test case, output on a new line the minimum number of seats required to be added.
Constraints
Sample Input 1
4
1 1
12 34
50 49
49 50
Sample Output 1
0
22
0
1
Explanation
Test case : Exactly seat is available for enrolment, and exactly student is interested in taking up the course, hence addition of more seats is not required.
Test case : seats are available for enrolment but students are interested in taking up the course, hence the admins would have to add more seats to make sure that every student interested in the course gets a seat.
Test case : seats are available for enrolment and students are interested in taking up the course, hence addition of more seats is not required.
Test case : seats are available for enrolment, but students are interested in taking up the course, hence the admins would have to add more seat to make sure that every student interested in the course gets a seat.
Solution :
#include <iostream>
using namespace std;
int main() {
int t,a,b;
cin>>t;
while(t--){
cin>>a>>b;
if(b>=a)
cout<<b-a<<endl;
else
cout<<0<<endl;
}
return 0;
}
Group Assignment
Chef is hosting a party at his house and people are invited to it. Everyone has arrived and they are eager to make a group and chit-chat.
The person prefers to be in a group of exactly people (including himself). A person who is not in a group of preferred size gets upset. Find whether Chef would be able to assign every person to a group such that everyone remains happy.
Input Format
- The first line of input will contain a single integer , denoting the number of test cases.
- Each test case consists of multiple lines of input.
- The first line of each test case contains an integer — the number of people at the party.
- The next line contains the array — where denotes the preferred group size for person.
Output Format
For each test case, output YES
, if Chef can assign every person to a group such that everyone remains happy. Otherwise output NO
.
The output is case-insensitive, meaning that outputs such as yES
, YeS
, YES
and yes
mean the same.
Constraints
- Sum of over all test cases does not exceed .
Sample Input 1
4
5
2 3 2 3 3
5
5 5 5 5 5
5
3 2 2 3 2
4
4 4 4 3
Sample Output 1
YES
YES
NO
NO
Explanation
Test case :
- Person and can make a group (As both want to be in a group of ).
- Person , and can make a group (As they all want to be in a group of ).
So, there is a possible arrangement that Chef can make so that all of them are happy.
Test case :
- All of the people can make a group (As all want to be in a group of ).
So, there is a possible arrangement that Chef can make so that all of them are happy.
Test case : It can be shown that there is no possible arrangement that Chef can make so that all of them are happy.
Test case : It can be shown that there is no possible arrangement that Chef can make so that all of them are happy.
Solution :
#include <bits/stdc++.h>
using namespace std;
int main() {
int t;
cin>>t;
while(t--){
int a,cnt=0;
cin>>a;
int b[a];
map<int,int> m;
for(int i=0;i<a;i++){
cin>>b[i];
m[b[i]]++;
}
string ans ="YES";
for(auto j:m){
if(j.second%j.first!=0){
ans="NO";break;}}
cout<<ans<<endl;
}
return 0;
}