Chopsticks
SRM 570 · 2012-12-13 · by snuke
Problem Statement
Cat Carol wants to invite some of her friends to a lunch at her house. Carol has some chopsticks of possibly different lengths. Each of the invited guests must receive two chopsticks. Additionally, the two chopsticks given to each guest must have exactly the same length.
You are given a
Constraints
- length will contain between 1 and 50 elements, inclusive.
- Each element of length will be between 1 and 100, inclusive.
{5,5}
Returns: 1
Two chopsticks have the same length. Carol can invite one friend.
{1,2,3,2,1,2,3,2,1}
Returns: 4
Carol can make one pair of chopsticks of length 1, two pairs of chopsticks of length 2, and one pair of chopsticks of length 3. She can invite four guests in total.
{1}
Returns: 0
Carol has only one chopstick. Carol can't invite anybody.
{1,2,3,4,5,6,7,8,9}
Returns: 0
No two chopsticks have the same length. Carol can't invite anybody.
{1,1,2,3,5,8,13,21,34,55,89}
Returns: 1
Submissions are judged against all 79 archived test cases, of which 5 are shown here. Case numbers match the judge’s.
Language: C++17 · define a public class Chopsticks with a public method int getmax(vector<int> length) · 79 test cases · 2 s / 256 MB per case