Problem
Mr. Chef is the manager of the Code cinemas and after a long break, the theatres are now open to the public again. To compensate for the loss in revenue due to Covid-19, Mr. Chef wants to maximize the profits for every show from now on and at the same time follow the guidelines set the by government. The guidelines are:
- If two people are seated in the same row, there must be at least one empty seat between them.
- If two people are seated in different rows, there must be at least one completely empty row between them. That is, if there are people seated in rows and where , there must be some row such that and nobody is seated in row .
Given the information about the number of rows and the number of seats in each row, find the maximum number of tickets Mr. Chef can sell.
Input Format
- The first line of input will contain a single integer , denoting the number of test cases. The description of test cases follows.
- Each test case consists of a single line of input containing two space-separated integers — the number of rows and the number of seats in each row, respectively.
Output Format
For each test case, output a single line containing one integer – the maximum number of tickets Mr. Chef can sell.
Constraints
Sample 1:
3 1 5 3 3 4 4
3 4 4
Explanation:
Test Case 1: There is only one row with five seats. Mr. Chef can sell a maximum of 3 tickets for seat numbers 1, 3 and 5.
Test Case 2: There are three rows with three seats each. Mr. Chef can sell a maximum of 4 tickets, for seats at the start and end of row numbers 1 and 3.
Test Case 3: There are four rows with four seats each. Mr. Chef can sell a maximum of 4 tickets, for example by choosing the seats at the start and end of row numbers 1 and 4.
Program :
#include<stdio.h>
#include<math.h>
int main()
{
int a,b=0,j,k,n,t,i,count;
scanf("%d",&t);
while(t--)
{
b=1,count=0;
scanf("%d %d",&n,&k);
for(j=1;j<=n;j=j+2)
{
b=1;
while(b<=k)
{
b=b+2;
count++;
}
}
printf("%d\n",count);
}
}
0 Comments