#P16861. [GKS 2021 #G] Dogs and Cats

[GKS 2021 #G] Dogs and Cats

Problem Description

You work for an animal shelter and you are responsible for feeding the animals. You already prepared DD portions of dog food and CC portions of cat food.

There are a total of NN 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 SS of NN characters CC and DD represents the order of cats and dogs in the line. The ii-th character is equal to CC if the ii-th animal in the line is a cat. Similarly, the ii-th character is equal to DD if the ii-th animal in the line is a dog.

The animals are fed in the order they stay in the line. Each dog eats exactly 11 portion of dog food and similarly each cat eats exactly 11 portion of cat food. Moreover, you have extra portions of cat food. Every time a dog eats food, you bring MM 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, TT. TT test cases follow.

The first line of each test case contains four integers NN, DD, CC, and MM: 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 SS of length NN representing the arrangement of animals.

Output Format

For each test case, output 11 line containing Case #xx: yy, where xx is the test case number (starting from 11) and yy is YES if all the dogs will be fed and NO otherwise.

3
6 10 4 0
CCDCDD
4 1 2 0
CCCC
4 2 1 0
DCCD
Case #1: YES
Case #2: YES
Case #3: NO
2
12 4 2 2
CDCCCDCCDCDC
8 2 1 3
DCCCCCDC
Case #1: YES
Case #2: NO

Hint

In Sample Case #11, there are 1010 portions of dog food and 44 portions of cat food.

  • 11. The 11st 22 animals are cats, so after they eat, 22 portions of cat food remain.
  • 22. Then a dog eats 11 portion of dog food. Now, there are 99 portions of dog food left.
  • 33. Next, a cat eats 11 portion of cat food, reducing the number of portions of cat food to 11.
  • 44. The last 22 animals are dogs and they each eat 11 portion of dog food.

So in this case, all the dogs are able to eat.

In Sample Case #22, there are no dogs. Hence, all (00) dogs will be able to eat trivially.

In Sample Case #33, the cat before the 22nd dog will not be able to eat because there will not be enough portions of cat food. Hence, the 22nd dog will also not eat.

Limits

1T1001 \le T \le 100.

1N1041 \le N \le 10^4.

0D,C1060 \le D, C \le 10^6.

SS consists of only characters CC and DD.

Test Set 11

M=0M = 0.

Test Set 22

0M1060 \le M \le 10^6.