PROBLEM LINK:
Practice
Contest: Division 1
Contest: Division 2
Contest: Division 3
Contest: Division 4
Author: raysh07
Tester: sushil2006
Editorialist: raysh07
DIFFICULTY:
Cakewalk
PREREQUISITES:
None
PROBLEM:
Chef has X money, movie ticket costs 100 and then each popcorn bucket costs 50. At most how many popcorn buckets will Chef be able to buy?
EXPLANATION:
Chef has X - 100 money left over after buying the movie ticket, which he will use to buy the popcorn buckets.
Since each popcorn bucket costs 50, he will be able to buy \lfloor \frac{X - 100}{50} \rfloor where \lfloor . \rfloor denotes the floor function.
Simply implementing this formula in the language of your choice works, for example in C++, normal division is already floor division. But in python, you must use A//B instead of A/B for floor division.
TIME COMPLEXITY:
\mathcal{O}(1) per testcase.
CODE:
Editorialist's Code (C++)
#include <bits/stdc++.h>
using namespace std;
int main()
{
int x; cin >> x;
cout << ((x - 100) / 50) << "\n";
}