CF1057C.Tanya and Colored Candies

普及/提高-

通过率:0%

AC君温馨提醒

该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。

题目描述

There are nn candy boxes in front of Tania. The boxes are arranged in a row from left to right, numbered from 11 to nn . The ii -th box contains rir_i candies, candies have the color cic_i (the color can take one of three values ​​— red, green, or blue). All candies inside a single box have the same color (and it is equal to cic_i ).

Initially, Tanya is next to the box number ss . Tanya can move to the neighbor box (that is, with a number that differs by one) or eat candies in the current box. Tanya eats candies instantly, but the movement takes one second.

If Tanya eats candies from the box, then the box itself remains in place, but there is no more candies in it. In other words, Tanya always eats all the candies from the box and candies in the boxes are not refilled.

It is known that Tanya cannot eat candies of the same color one after another (that is, the colors of candies in two consecutive boxes from which she eats candies are always different). In addition, Tanya's appetite is constantly growing, so in each next box from which she eats candies, there should be strictly more candies than in the previous one.

Note that for the first box from which Tanya will eat candies, there are no restrictions on the color and number of candies.

Tanya wants to eat at least kk candies. What is the minimum number of seconds she will need? Remember that she eats candies instantly, and time is spent only on movements.

输入格式

The first line contains three integers nn , ss and kk ( 1n501 \le n \le 50 , 1sn1 \le s \le n , 1k20001 \le k \le 2000 ) — number of the boxes, initial position of Tanya and lower bound on number of candies to eat. The following line contains nn integers rir_i ( 1ri501 \le r_i \le 50 ) — numbers of candies in the boxes. The third line contains sequence of nn letters 'R', 'G' and 'B', meaning the colors of candies in the correspondent boxes ('R' for red, 'G' for green, 'B' for blue). Recall that each box contains candies of only one color. The third line contains no spaces.

输出格式

Print minimal number of seconds to eat at least kk candies. If solution doesn't exist, print "-1".

输入输出样例

  • 输入#1

    5 3 10
    1 2 3 4 5
    RGBRR
    

    输出#1

    4
    
  • 输入#2

    2 1 15
    5 6
    RG
    

    输出#2

    -1
    

说明/提示

The sequence of actions of Tanya for the first example:

  • move from the box 33 to the box 22 ;
  • eat candies from the box 22 ;
  • move from the box 22 to the box 33 ;
  • eat candy from the box 33 ;
  • move from the box 33 to the box 44 ;
  • move from the box 44 to the box 55 ;
  • eat candies from the box 55 .

Since Tanya eats candy instantly, the required time is four seconds.

首页