WinterAndMandarins
SRM 601 · 2013-06-25 · by Witaliy
Problem Statement
It's winter time! Time to eat a lot of mandarins with your friends.
You have several bags with mandarins.
You are given an
Constraints
- bags will contain between 2 and 50 elements, inclusive.
- Each element of bags will be between 1 and 1,000,000,000, inclusive.
- K will be between 2 and N, inclusive, where N is the number of elements in bags.
{10, 20, 30}
2
Returns: 10
There are three ways to choose two bags in this case: {10, 20}, {20, 30}, and {10, 30}. Both in the first case and in the second case the difference between the largest and the smallest number of mandarins is 10. In the third case the difference is 20. Thus, the smallest possible difference is 10.
{4, 7, 4}
3
Returns: 3
{4, 1, 2, 3}
3
Returns: 2
{5, 4, 6, 1, 9, 4, 2, 7, 5, 6}
4
Returns: 1
{47, 1000000000, 1, 74}
2
Returns: 27
Submissions are judged against all 116 archived test cases, of which 5 are shown here. Case numbers match the judge’s.
Language: C++17 · define a public class WinterAndMandarins with a public method int getNumber(vector<int> bags, int K) · 116 test cases · 2 s / 256 MB per case