CF1057C.Tanya and Colored Candies

普及+/提高

通过率:0%

时间限制:2.00s

内存限制:256MB

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.

塔尼娅面前有 nn 个糖果盒。这些盒子从左到右排成一排,编号为 11 到 nn。第 ii 个盒子中有 rir_i 颗糖果,糖果颜色为 cic_i(颜色只能是红、绿、蓝三种之一)。每个盒子内部的所有糖果颜色均相同(即均为 cic_i)。

初始时,塔尼娅位于编号为 ss 的盒子旁。塔尼娅每次可以移动至相邻的盒子(即编号相差 11 的盒子),或吃掉当前盒子中的所有糖果。塔尼娅吃糖果是瞬间完成的,但每次移动需耗时 11 秒。

若塔尼娅吃掉某个盒子中的糖果,则该盒子本身仍保留在原位,但其中不再有糖果。换言之,塔尼娅每次吃糖果总是吃光整个盒子中的全部糖果,且盒子中的糖果不会被补充。

已知塔尼娅不能连续吃两种颜色相同的糖果(即:她所吃的任意两个相邻盒子的糖果颜色必须互不相同)。此外,塔尼娅的食欲持续增长,因此她在后续每一个吃糖果的盒子中所吃到的糖果数量必须严格多于前一个吃糖果的盒子。

注意:对于塔尼娅吃糖果的第一个盒子,对其颜色和糖果数量均无任何限制。

塔尼娅希望总共吃掉至少 kk 颗糖果。她所需的最少秒数是多少?请记住:吃糖果本身不耗时,时间仅花费在移动上。

输入格式

The first line contains three integers nn, ss and kk (1≤n≤501 \le n \le 50, 1≤s≤n1 \le s \le n, 1≤k≤20001 \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 (1≤ri≤501 \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.

第一行包含三个整数 nn、ss 和 kk(1≤n≤501 \le n \le 50,1≤s≤n1 \le s \le n,1≤k≤20001 \le k \le 2000)—— 分别表示盒子的数量、塔尼娅的初始位置以及她需要吃掉的糖果数量的下界。
第二行包含 nn 个整数 rir_i(1≤ri≤501 \le r_i \le 50)—— 表示各盒子中糖果的数量。
第三行包含一个由 nn 个字母组成的字符串,每个字母为 'R'、'G' 或 'B',表示对应盒子中糖果的颜色('R' 表示红色,'G' 表示绿色,'B' 表示蓝色)。注意:每个盒子中仅含一种颜色的糖果。该行字符串中不含空格。

输出格式

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

输出吃完至少 kk 颗糖果所需的最少秒数。若无解,输出 "-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.

塔尼娅在第一个样例中的操作序列如下:

  • 从第 33 个盒子移动到第 22 个盒子;
  • 吃掉第 22 个盒子中的糖果;
  • 从第 22 个盒子移动到第 33 个盒子;
  • 吃掉第 33 个盒子中的一颗糖果;
  • 从第 33 个盒子移动到第 44 个盒子;
  • 从第 44 个盒子移动到第 55 个盒子;
  • 吃掉第 55 个盒子中的糖果。

由于塔尼娅吃糖果是瞬间完成的,因此所需时间为四秒。

输入解题思路,AI测评打分。不知道怎么写?

首页