Logo
(追記) (追記ここまで)

12538번 - Closing the Loop (Large) 다국어

시간 제한메모리 제한제출정답맞힌 사람정답 비율
5 초 512 MB71706798.529%

문제

Given a bag full of rope segments, you will build the longest loop of rope while alternating colors. The bag contains S segments and each segment will either be blue (B) or red (R). You are required to alternate between colors and because of this requirement you might not use every segment in the bag. If you only have segments of a single color, you will not be able to tie any knots and should output 0. Each segment length is provided in centimeters and each knot in the loop consumes one centimeter of length from the loop. In other words, a knot consumes one-half of a centimeter from of the two segment it connects.

Note that pieces of string that have length 1, if used in making the cycle, might get reduced to just a pair of knots of total length 0. This is allowed, and each such piece counts as having been used.

입력

The first line of input gives the number of cases, N.
N test cases follow. For each test case there will be:

  • One line containing the value S, the number of rope segments in the bag.
  • One line containing a space separated list of S values. Each value L indicates the segment length in centimeters followed by the letter B or R to indicate the segment color.

Limits

  • 1 ≤ number of rope segments (S) ≤ 1000
  • 1 ≤ length of a rope segment (L) ≤ 100
  • N ≤ 50

출력

For each test case, output one line containing "Case #x: " followed by the maximum length of the rope loop that can be generated with the rope segments provided.

제한

예제 입력 1

4
1
5B
4
6R 1B 7R 3B
7
5B 4R 3R 2R 5R 4R 3R
2
20B 20R

예제 출력 1

Case #1: 0
Case #2: 13
Case #3: 8
Case #4: 38

힌트

출처

Contest > Google > Google's Coding Competitions > Code Jam Africa and Arabia 2011 > Qualification Round A2번

채점 및 기타 정보

  • 예제는 채점하지 않는다.
(追記) (追記ここまで)

출처

대학교 대회

  • 사업자 등록 번호: 541-88-00682
  • 대표자명: 최백준
  • 주소: 서울시 서초구 서초대로74길 29 서초파라곤 412호
  • 전화번호: 02-521-0487 (이메일로 연락 주세요)
  • 이메일: contacts@startlink.io
  • 통신판매신고번호: 제 2017-서울서초-2193 호

AltStyle によって変換されたページ (->オリジナル) /