P16861 [GKS 2021 #G] Dogs and Cats
Description
You work for an animal shelter and you are responsible for feeding the animals. You already prepared $D$ portions of dog food and $C$ portions of cat food.
There are a total of $N$ animals waiting in a line, some of which are dogs and others are cats. It might be possible that all the animals in the line are dogs or all the animals are cats. A string $S$ of $N$ characters $C$ and $D$ represents the order of cats and dogs in the line. The $i$-th character is equal to $C$ if the $i$-th animal in the line is a cat. Similarly, the $i$-th character is equal to $D$ if the $i$-th animal in the line is a dog.
The animals are fed in the order they stay in the line. Each dog eats exactly $1$ portion of dog food and similarly each cat eats exactly $1$ portion of cat food. Moreover, you have extra portions of cat food. Every time a dog eats food, you bring $M$ extra portions of cat food for cats.
Animals have to be fed in the order they wait in line and an animal can only eat if the animal before it has already eaten. That means that if you run out of dog (or cat) food portions and a dog (or a cat) is about to get fed, the line will not move, as all the animals will wait patiently.
You need to determine if in this scenario all the dogs in the line will be fed. Note that this means that some cats might remain in the line, but worry not, you will eventually feed them later!
Input Format
The first line of the input gives the number of test cases, $T$. $T$ test cases follow.
The first line of each test case contains four integers $N$, $D$, $C$, and $M$: the number of animals, the initial number of dog food portions, the initial number of cat food portions, and the additional portions of cat food that we add after a dog eats a portion of dog food, respectively.
The next line contains a string $S$ of length $N$ representing the arrangement of animals.
Output Format
For each test case, output $1$ line containing Case #$x$: $y$, where $x$ is the test case number (starting from $1$) and $y$ is `YES` if all the dogs will be fed and `NO` otherwise.
Explanation/Hint
In Sample Case #$1$, there are $10$ portions of dog food and $4$ portions of cat food.
- $1$. The $1$st $2$ animals are cats, so after they eat, $2$ portions of cat food remain.
- $2$. Then a dog eats $1$ portion of dog food. Now, there are $9$ portions of dog food left.
- $3$. Next, a cat eats $1$ portion of cat food, reducing the number of portions of cat food to $1$.
- $4$. The last $2$ animals are dogs and they each eat $1$ portion of dog food.
So in this case, all the dogs are able to eat.
In Sample Case #$2$, there are no dogs. Hence, all ($0$) dogs will be able to eat trivially.
In Sample Case #$3$, the cat before the $2$nd dog will not be able to eat because there will not be enough portions of cat food. Hence, the $2$nd dog will also not eat.
### Limits
$1 \le T \le 100$.
$1 \le N \le 10^4$.
$0 \le D, C \le 10^6$.
$S$ consists of only characters $C$ and $D$.
**Test Set $1$**
$M = 0$.
**Test Set $2$**
$0 \le M \le 10^6$.