# CE20201D Editorial

Author: shanvid
Tester: shanvid
Editorialist: shanvid

Medium

Maths,Matrix

# PROBLEM:

During a MCQ test, a classroom decided to cheat together. There are in total N x M benches.[N rows M columns]. Each bench has one student. With a total of NxM number of students[No benches are empty]. Now there is only one master cheat sheet in the class with student at bench (0,0). Each student requires 5 min to mark all the answers. After marking all the answers, the student passes the sheet to the next student in the column. When the sheet reaches to the last bench in the row, the sheet is passed to the adjacent bench. No student can receive the sheet twice. All students can copy like this but the invigilator is in the class from the start of the test. But to their luck, the invigilator only monitors one column at a time only for exactly 6 min. When the invigilator monitors the column, students in that column cannot mark the answers but as soon as he leaves, the can continue the process. At the start of the test the invigilator is at the Mth row. The invigilator monitors all the columns in a circular manner[Eg for 3x4 arrangement he goes 4,3,2,1,2,3,4,3, …].

Find how much time will the class require so that every student finishes marking all the answers.

### Input:

• First line contains the N number to rows
• Second line contains M number of columns.

### Output:

Output should be a integer number depicting time required.

# EXPLANATION:

### Sample Input:

``````2
3
``````

### Sample Output:

``````69
``````

### EXPLANATION:

[ S(0,0) -> Student at C0, R0. C1 -> Column 1, Column from 0 to m-1, Rows from 0 to n-1] Sheet will start at S(0,0) and Invigilator at C2. S(0,0) will take 5min, I will be at C2,S(1,0) will take 5 minutes, I will be at C1. Now sheet needs to be passed on to C1 but Invigilator is at C1 so wait. Then Invigilator at C0 so wait, Invigilator at C1 so wait. Then invigilator goes to C2 then sheet can be passed to C1. Repeat this steps for all students

# SOLUTIONS:

``````#include<iostream>

using namespace std;

main()
{
int n,m;
cin>>n;
cin>>m;
char dir='l';
int etime = 0,icol=(m-1),scol=0,srow=0;
for(int i=0;i<srow < n && scol < m;i++){
etime++;
if(etime%6==0 && etime !=0){
if(dir=='l'){
icol--;
}
else{
icol++;
}
};
if(icol==0 && dir == 'l') dir = 'r';
else if(icol==(m-1) && dir == 'r') dir ='l';

if(scol != icol){
if(etime%5 == 0 && srow != (n-1)){
srow ++;
}
else if(etime%5 == 0 && srow == (n-1) && (scol + 1) != icol){
srow =0;
scol ++;
}
}

}
cout << (etime-1);
}``````