Connection Status:
Competition Arena > DeerInZooDivTwo
SRM 578 · 2012-12-13 · by tozangezan · Brute Force, Simple Math
Class Name: DeerInZooDivTwo
Return Type: int[]
Method Name: getminmax
Arg Types: (int, int)
Problem Statement

Problem Statement

Brus and Gogo came to the zoo today. It's the season when deer shed their antlers. There are N deer in the zoo. Initially, each deer had exactly two antlers, but since then some deer may have lost one or both antlers. (Now there may be some deer with two antlers, some with one, and some with no antlers at all.)

Brus and Gogo went through the deer enclosure and they collected all the antlers already lost by the deer. The deer have lost exactly K antlers in total. Brus and Gogo are now trying to calculate how many deer have not lost any antlers yet.

Return a int[] with exactly two elements {x,y}, where x is the smallest possible number of deer that still have two antlers, and y is the largest possible number of those deer.

Constraints

  • N will be between 1 and 1000, inclusive.
  • K will be between 0 and 2N, inclusive.
Examples
0)
1
0
Returns: {1, 1 }
1)
1
1
Returns: {0, 0 }
2)
1
2
Returns: {0, 0 }
3)
2
0
Returns: {2, 2 }
4)
2
1
Returns: {1, 1 }
10)
3
2
Returns: {1, 2 }

There are two possibilities: Either the K=2 antlers come from two different deer, or they come from the same deer. In the first case, there is 1 deer with two antlers (and two other with one antler each), in the second case there are 2 deer with two antlers each (and one deer with none).

15)
10
0
Returns: {10, 10 }

All deer still have 2 horns.

Submissions are judged against all 73 archived test cases, of which 7 are shown here. Case numbers match the judge’s.

Coding Area

Language: C++17 · define a public class DeerInZooDivTwo with a public method vector<int> getminmax(int N, int K) · 73 test cases · 2 s / 256 MB per case

Submitting as anonymous