#P5425. Maximize the Minimum Distance for Cow Grouping
Maximize the Minimum Distance for Cow Grouping
Maximize the Minimum Distance for Cow Grouping
Farmer John wants to divide his N cows, numbered from 1 to N (with N ≤ 7500), into K non‐empty groups (2 ≤ K ≤ N). When two cows from different groups meet, they must travel a certain distance. Specifically, for any two cows x and y with 1 ≤ x < y ≤ N, the distance they are willing to walk is given by the formula:
$$d(x,y) = (2019201913\,x + 2019201949\,y)\ \bmod\ 2019201997$$
Because $$2019201913\equiv -84 \quad\text{and}\quad 2019201949\equiv -48 \quad\text{(mod }2019201997\text{)},$$ and since 84x + 48y is always less than 2019201997 for the given constraints, the above formula can be simplified to:
$$d(x,y)=2019201997-84x-48y.$$
Consider a particular grouping of the N cows into K groups. Let M be the minimum distance between any two cows that belong to different groups. Farmer John wants to maximize this value M by choosing an optimal partition.
Your task is to compute the maximum possible value of M given the numbers N and K.
Hint: It can be shown that the optimal solution yields a value of
$$M = 2019201997 - 84\,(K-1) - 48\,N.$$
Use this fact to implement an efficient solution.
inputFormat
The input consists of a single line containing two space‐separated integers: N and K.
N is the number of cows (1 ≤ N ≤ 7500), and K is the number of groups (2 ≤ K ≤ N).
outputFormat
Output a single integer, which is the maximum possible value of M, the minimum distance between any two cows in different groups.
sample
3 2
2019201769
</p>