[Hihocoder] Magic Box

Source: Internet
Author: User

Topic 1:magic Box time limit: 10000ms single point time limit: 1000ms memory limit: 256MB description

The circus clown Sunny has a magic box. When the circus are performing, Sunny puts some balls into the box one by one. The balls is 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 is X, Y, Z, all balls in the box vanish. Given x, Y, z and the sequence in which Sunny put the balls, you be to find what's the maximum number of balls in the Bo X 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 is 4, 1, 2 respectively. The differences is exactly 1, 2, 3. (| Cr-cy|=3, | Cy-cb|=1, | cb-cr|=2) then all the 7 balls vanish. Finally There is 4 balls in the box, after Sunny puts the remaining balls. So the box contains 7 balls for most, after Sunny puts the first 7 balls and before they vanish.

Input

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 are no more than 200.

For 100% data, the length of the sequence are no more than 20,000, 0 <= x, y, Z <= 20.

Output

The maximum number of balls in the box ever.

Tips

Another Sample

Sample Input Sample Output
0 0 0
Rbyrrby
4

Sample input
1 2 3RRYBRBRYBRY
Sample output
7
#include <string>#include<iostream>#include<cmath>//#include <fstream>using namespacestd;intMain () {intr,y,b; stringBS; //ifstream cin ("In.txt");     while(cin>>r>>y>>b>>s) {        intAns =0, tmp=0, CR,CY,CB; CR= cy = cb =0;  for(inti =0; I < s.size (); ++i) {tmp++; if(S[i] = ='R') cr++; Else if(S[i] = ='Y') cy++; Elsecb++; if(ABS (CR-CY)! =b)Continue; if(ABS (CR-CB)! =y)Continue; if(ABS (CY-CB)! =R)Continue; if(tmp >ans) ans=tmp; TMP=0; CR= cy = cb =0; } cout<< ans <<Endl; }    return 0;}

[Hihocoder] Magic Box

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.