Data Structures & AlgorithmsVery hardICPC regional · Codeforces Div2 D
Stalls are at positions [1, 2, 8, 4, 9, 15, 17] on a line. You must place C = 4 cows in distinct stalls to maximise the MINIMUM distance between any two cows. What is that maximum minimum distance?
- A. 3
- B. 8
- C. 4
- D. 2
Correct answer: A. 3
Binary search on the answer d: check whether greedily placing each cow at the first stall at least d beyond the previous one fits all cows. The check is monotone, so the largest feasible d is the answer. Dividing the span evenly by the cow count ignores where the stalls actually are.
Practise more Arrays, Strings, Linked Lists, Stacks, Queues and Hashing questionsArrays, Strings, Linked Lists, Stacks, Queues and Hashing: notes and key points
More Arrays, Strings, Linked Lists, Stacks, Queues and Hashing questions
- Books have page counts [12, 34, 67, 90, 25, 40, 18] in this fixed order. They are split among K = 3 students so that each student receives…
- Koko has banana piles [3, 6, 7, 11] and H = 8 hours. Each hour she eats up to k bananas from ONE pile (if a pile has fewer, she finishes…
- For the array [19, 4, 33, 12, 7, 29], find the smallest positive integer d such that the sum of ceil(x / d) over all elements is at most…
- In a 3 × 5 multiplication table (entries i × j for 1 ≤ i ≤ 3, 1 ≤ j ≤ 5), with repeats counted, what is the 7-th smallest entry?
- Flowers bloom on the days [1, 10, 3, 10, 2] (one flower per position). You need m = 3 bouquets, and each bouquet needs k = 1 adjacent…
- Wood sticks have lengths [232, 124, 456] (integers). You need K = 7 pieces of EQUAL integer length, and you may cut each stick into as…