Connection Status:
Competition Arena > FoxAndVacation
SRM 561 · 2012-06-05 · by cgy4ever · Greedy
Class Name: FoxAndVacation
Return Type: int
Method Name: maxCities
Arg Types: (int, vector<int>)
Problem Statement

Problem Statement

Fox Ciel is planning to visit the Tourist Kingdom for total days. This kingdom is full of lovely cities. During her stay Ciel would like to visit as many different cities as possible. She cannot visit more than one city on the same day.


Additionally, different cities may require her to stay for a different number of days. For each i, city i only counts as visited if Ciel spends at least d[i] days in the city.


You are given the int total and the int[] d. Return the maximal number of cities she can visit during her vacation.

Notes

  • When solving the task, ignore travel times. (Fox Ciel always travels at night, and she can travel between any two cities very quickly.)

Constraints

  • total will be between 1 and 50, inclusive.
  • d will contain between 1 and 50 elements, inclusive.
  • Each element of d will be between 1 and 50, inclusive.
Examples
0)
5
{2,2,2}
Returns: 2

Fox Ciel's vacation lasts for 5 days. She needs at least 2 days to visit each of the cities, so she can visit at most 2 of them.

1)
5
{5,6,1}
Returns: 1

She can only visit one city: either city 0, or city 2.

2)
5
{6,6,6}
Returns: 0

This time the poor Fox Ciel cannot visit any city during her summer vacation.

3)
6
{1,1,1,1,1}
Returns: 5

In this test case Ciel can visit all five cities. Note that at the end of her trip each city either does count as visited, or it does not -- there is no way to "visit" the same city twice.

4)
10
{7,1,5,6,1,3,4}
Returns: 4

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

Coding Area

Language: C++17 · define a public class FoxAndVacation with a public method int maxCities(int total, vector<int> d) · 133 test cases · 2 s / 256 MB per case

Submitting as anonymous