PROBLEM LINK:
Practice
Contest: Division 1
Contest: Division 2
Contest: Division 3
Contest: Division 4
Author: raysh07
Tester: archit
Editorialist: raysh07
DIFFICULTY:
Cakewalk
PREREQUISITES:
None
PROBLEM:
Your favourite player scored N runs off 100 balls. Each ball got him 0, 1, 2, 3, 4 or 6 runs. Find the maximum number of 6 ers he could have scored.
EXPLANATION:
Let \lfloor x \rfloor denote the greatest integer not exceeding x, and then \lfloor \frac{x}{y} \rfloor represents the result of x divided by y but rounded down.
The answer is \lfloor \frac{N}{6} \rfloor.
This is because, first of all, it is impossible for the answer to be higher, since that many 6 s would exceed N.
Also, it is possible for our player to score that many runs because he could have got 6 on \lfloor \frac{N}{6} \rfloor balls, and then N - \lfloor \frac{N}{6} \rfloor single runs, and the other balls scored for 0.
Thus, you only have to input N and print \lfloor \frac{N}{6} \rfloor. For example, in C++, normal division is automatically rounded down. In python, you have to do n // 6.
TIME COMPLEXITY:
\mathcal{O}(1) per testcase.
CODE:
Editorialist's Code (C++)
#include <bits/stdc++.h>
using namespace std;
int main(){
int n; cin >> n;
cout << (n / 6) << "\n";
return 0;
}