Magic Box
Time Limit: 1 Sec Memory Limit: 256 MB
描述
The circus clown Sunny has a magic box. When the circus is performing, Sunny puts some balls into the box one by one. The balls are in three colors: red(R), yellow(Y) and blue(B). Let Cr, Cy, Cb denote the numbers of red, yellow, blue balls in the box. Whenever the differences among Cr, Cy, Cb happen to be x, y, z, all balls in the box vanish. Given x, y, z and the sequence in which Sunny put the balls, you are to find what is the maximum number of balls in the box ever.
For example, let’s assume x=1, y=2, z=3 and the sequence is RRYBRBRYBRY. After Sunny puts the first 7 balls, RRYBRBR, into the box, Cr, Cy, Cb are 4, 1, 2 respectively. The differences are exactly 1, 2, 3. (|Cr-Cy|=3, |Cy-Cb|=1, |Cb-Cr|=2) Then all the 7 balls vanish. Finally there are 4 balls in the box, after Sunny puts the remaining balls. So the box contains 7 balls at most, after Sunny puts the first 7 balls and before they vanish.

传送门:HIHO1135

输入

Line 1: x y z Line 2: the sequence consisting of only three characters 'R', 'Y' and 'B'. For 30% data, the length of the sequence is no more than 200. For 100% data, the length of the sequence is no more than 20,000, 0 <= x, y, z <= 20.

输出

The maximum number of balls in the box ever.

Sample Input

1
2
1 2 3
RRYBRBRYBRY

Sample Output

1
7

题解

注意细节,最后要再判一次留下的是不是最大的
## AC code:(不包含输入类)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
import java.io.*;  
import java.util.*;
public class Main {
public static void main(String[] args) {
Scanner sc= new Scanner(System.in);
while(sc.hasNext()){
int x=sc.nextInt();
int y=sc.nextInt();
int z=sc.nextInt();
int Cr=0;
int Cy=0;
int Cb=0;
int count=0;
int MAX=-1;
sc.nextLine();
String s=sc.nextLine();
PriorityQueue<Integer>queue=new PriorityQueue<Integer>();
queue.add(x);
queue.add(y);
queue.add(z);
x=queue.poll();
y=queue.poll();
z=queue.poll();
//System.out.println(x+" "+y+" "+z);
for(int i=0;i<s.length();i++){
if(s.charAt(i)=='R'){
Cr++;
}
if(s.charAt(i)=='Y'){
Cy++;
}
if(s.charAt(i)=='B'){
Cb++;
}
count++;
queue.add(Math.abs(Cr-Cy));
queue.add(Math.abs(Cy-Cb));
queue.add(Math.abs(Cr-Cb));
int min=queue.poll();
int mid=queue.poll();
int max=queue.poll();
//System.out.println(min+""+mid+""+max);
if(x==min&&y==mid&&z==max){
MAX=Math.max(MAX, count);
count=0;
Cr=0;
Cy=0;
Cb=0;
}
}
MAX=Math.max(MAX, count); //再判一次
System.out.println(MAX);
}
}
}