The parking lot of a department store will have three types of parking spaces based on the size of the car: small, medium, and large parking spaces.
The small parking spaces are suitable for cars with sizes ranging from 1 to 199, medium parking spaces are suitable for cars with sizes ranging from 200 to 499, and cars with sizes equal to or greater than 500 are suitable for parking in large parking spaces.
Each parking lot allocates a different number of parking spaces for different types of cars. To make more efficient use of the space, when a type of parking space is full, cars can park in larger parking spaces.
For example, if the small parking spaces are full, small cars can park in the medium-sized parking spaces. However, if the large parking spaces are full, cars cannot park in the medium or small parking spaces.
Please help calculate the maximum number of cars that can be parked in the current parking lot.
Sample Inputs/Outputs
Sample Input(s) | Sample Output(s) |
---|---|
The first line contains three integers S, M, and L (1 ≤ S ≤ 100, 1 ≤ M ≤ 100, 1 ≤ L ≤ 100), representing the number of small, medium, and large parking spaces, respectively.
The second line contains a positive integer N (1 ≤ N ≤ 300), indicating the number of cars to be parked. The third line contains N positive integers X_i (1 ≤ X ≤ 1000, 1 ≤ i ≤ N), representing the size of each car. Adjacent numbers in the input are separated by a single space. | Output a single number representing the maximum number of cars that can be parked. |
2 1 1 4 20 30 40 50 | 4 |
4 1 2 7 800 400 100 250 600 300 650 | 4 |
3 4 0 8 210 190 170 150 130 110 900 70 | 7 |
Thought Process
Declare an array and store the values of S, M, and L received in positions 0 to 2 of this array.
Declare a variable Start and set it to 0 if the car is small, 1 if it's medium, and 2 if it's large.
Run a for loop from Start to 3. If array[i] > 0, subtract array[i] and increment the answer variable by 1. Remember to break out of the for loop. Finally, output the answer variable.
Sample Code-ZeroJudge K513: Parking Slot
#include <iostream>
using namespace std;
int main() {
cin.sync_with_stdio(0);
cin.tie(0);
int arr[3] = {}, N, ans = 0;
cin >> arr[0] >> arr[1] >> arr[2] >> N;
for (int i = 0; i<N; i++)
{
int tmp, start;
cin >> tmp;
if (tmp <= 199) start = 0;
else if (tmp <= 499) start = 1;
else start = 2;
for (int j = start; j<3; j++)
{
if (arr[j] > 0)
{
arr[j]--;
ans++;
break;
}
}
}
cout << ans << "\n";
}
//ZeroJudge K513
//Dr. SeanXD