BRUNCH - Editorial

PROBLEM LINK:

Practice
Contest: Division 1
Contest: Division 2
Contest: Division 3
Contest: Division 4

Author: notsoloud
Tester: raysh07
Editorialist: iceknight1093

DIFFICULTY:

TBD

PREREQUISITES:

None

PROBLEM:

Chef has 20 neighbors, each of whom want Y plates of food.
Chef cooked X plates - how many of them can he feed completely?

EXPLANATION:

Suppose Chef wants to feed k neighbors.

Each neighbor wants Y plates of food, so k neighbors will require k\cdot Y plates in total.
This means we must have k\cdot Y \leq X, since there are only X plates of food in total.
Moving Y to the other side, this becomes k \leq \left\lfloor \frac{X}{Y} \right\rfloor as an upper bound on k.
Here, \left\lfloor \ \right\rfloor denotes the floor function.

Further, we must also have k \leq 20, since there are only 20 neighbors.

Putting both constraints together, we see that the answer is just

\min\left(20, \left\lfloor \frac{X}{Y} \right\rfloor\right)

TIME COMPLEXITY

\mathcal{O}(1) per testcase.

CODE:

Editorialist's code (C++)
#include <iostream>
using namespace std;

int main() {
	int t; cin >> t;
	while (t--) {
	    int x, y; cin >> x >> y;
	    cout << min(20, x/y) << '\n';
	}
	return 0;
}
Editorialist's code (Python)
for _ in range(int(input())):
    x, y = map(int, input().split())
    print(min(20, x//y))