日常刷题

简介: 日常刷题

codeforce-C. Brutality

https://codeforc.es/contest/1107/problem/C

You are playing a new famous fighting game: Kortal Mombat XII. You have to perform a brutality on your opponent’s character.

You are playing the game on the new generation console so your gamepad have 26 buttons. Each button has a single lowercase Latin letter from ‘a’ to ‘z’ written on it. All the letters on buttons are pairwise distinct.

You are given a sequence of hits, the i-th hit deals ai units of damage to the opponent’s character. To perform the i-th hit you have to press the button si on your gamepad. Hits are numbered from 1 to n.

You know that if you press some button more than k times in a row then it’ll break. You cherish your gamepad and don’t want to break any of its buttons.

To perform a brutality you have to land some of the hits of the given sequence. You are allowed to skip any of them, however changing the initial order of the sequence is prohibited. The total damage dealt is the sum of ai over all i for the hits which weren’t skipped.

Note that if you skip the hit then the counter of consecutive presses the button won’t reset.

Your task is to skip some hits to deal the maximum possible total damage to the opponent’s character and not break your gamepad buttons.

Input

The first line of the input contains two integers n and k (1≤k≤n≤2⋅105) — the number of hits and the maximum number of times you can push the same button in a row.

The second line of the input contains n integers a1,a2,…,an (1≤ai≤109), where ai is the damage of the i-th hit.

The third line of the input contains the string s consisting of exactly n lowercase Latin letters — the sequence of hits (each character is the letter on the button you need to press to perform the corresponding hit).

Output

Print one integer dmg — the maximum possible damage to the opponent’s character you can deal without breaking your gamepad buttons.

Examples

inputCopy

7 3

1 5 16 18 7 2 10

baaaaca

outputCopy

54

inputCopy

5 5

2 4 1 3 1000

aaaaa

outputCopy

1010

inputCopy

5 4

2 4 1 3 1000

aaaaa

outputCopy

1009

inputCopy

8 1

10 15 2 1 4 8 15 16

qqwweerr

outputCopy

41

inputCopy

6 3

14 18 9 19 2 15

cccccc

outputCopy

52

inputCopy

2 1

10 10

qq

outputCopy

10

Note

In the first example you can choose hits with numbers [1,3,4,5,6,7] with the total damage 1+16+18+7+2+10=54.

In the second example you can choose all hits so the total damage is 2+4+1+3+1000=1010.

In the third example you can choose all hits expect the third one so the total damage is 2+4+3+1000=1009.

In the fourth example you can choose hits with numbers [2,3,6,8]. Only this way you can reach the maximum total damage 15+2+8+16=41.

In the fifth example you can choose only hits with numbers [2,4,6] with the total damage 18+19+15=52.

In the sixth example you can change either first hit or the second hit (it does not matter) with the total damage 10.

题意:给n个数表示伤害,长度n的字符串命令执行,s[i]则受到对应的数字a[i]点伤害;同一个不能连续超过k次使用(有其他字符隔开可以继续用)问最大伤害;

* 因为java语言scanner方法输入数据太慢,做一些题的时候容易超时,故而用了BufferedReader。

* 其中PriorityQueue 队列的头指排序规则最小那个元素。如果多个元素都是最小值则随机选一个。

* 运用poll函数返回队列队首位置数字,即最小值

import java.io.*;
import java.util.*;
public class E3
{
    public static void main(String[] args) throws IOException
    {
        BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
        int i,N;
        String s[]=br.readLine().trim().split(" ");
        N=Integer.parseInt(s[0]);
        int K=Integer.parseInt(s[1]);
        int[] a=new int[N];
        s=br.readLine().trim().split(" ");
        for(i=0;i<N;i++) a[i]=Integer.parseInt(s[i]);
        PriorityQueue<Integer> PQ=new PriorityQueue<>();
        long sum=0;
        char str[]=br.readLine().trim().toCharArray();
        char cur='$';
        for(i=0;i<N;i++)
        {
            if(str[i]!=cur) PQ.clear();
            cur=str[i]; PQ.add(a[i]);
            sum+=a[i];
            if(PQ.size()>K) sum-=PQ.poll();
        }
        System.out.println(sum);
    }
}
相关文章
|
8天前
|
域名解析 人工智能 Linux
|
18天前
|
Linux Go 开发工具
手机上跑 DeepSeek 智能体:开源安卓客户端 DSH Go 安装与使用指南
DSH Go 是一款开源安卓客户端,将 DeepSeek Harness 智能体引擎装进手机:免 Root、免 Termux,一键安装即用;支持本机运行(内置 Ubuntu+Node.js)或远程接管电脑会话;具备插话打断、过程折叠、屏幕操控、端到端加密分享等特色功能,真正实现智能体“口袋化”。
16920 62
|
16天前
|
人工智能
Google 提示「所在地区不可用」?进不去 Antigravity 或 Gemini,先查账号这个设置
进不去 Antigravity 或 Gemini,提示所在地区不可用?三步查清 Google 账号关联地区、官方更正表单理由选法与改区注意事项。
Google 提示「所在地区不可用」?进不去 Antigravity 或 Gemini,先查账号这个设置
|
2天前
|
人工智能 安全 网络安全
|
5天前
|
云安全 数据采集 人工智能
|
7天前
|
Linux API iOS开发
【DSH】DeepSeek Harness新手保姆教程(下载+安装+配置+使用,2026最新实测)
DeepSeek Harness(dsh)是 DeepSeek AI 开源的智能体框架,秉持“一切皆插件”理念,支持读文件、改代码、执行命令、处理表格等自动化任务;免费开源,兼容 Win/macOS,需配 API 密钥使用。(239字)
1246 2
|
13天前
|
人工智能 开发工具 开发者
2026最新codex下载安装保姆级使用教程(下载+安装+登录+使用,含所有历史版本)
Codex 是 OpenAI 推出的开源 AI 编程智能体,跑在本地终端和桌面客户端里,能读懂整个代码仓库,一句自然语言就能让它改代码、执行命令、跑测试、修 Bug,支持 Windows、macOS、Linux 三大平台。本文把 Codex下载、安装、登录、汉化、基础使用一次讲全,并整理了国内用户最常踩的坑,跟着做 10 分钟就能跑起来。
2336 7
|
18天前
|
弹性计算 人工智能 API
Codex超详细入门指南(下载·安装·登录·上手,全版本覆盖,2026最新版)
建议收藏本教程,2026 全年各版本更新随时回来查阅。如果你在搭建过程中遇到任何问题,欢迎结合 阿里云工单系统 提交技术支持请求,或在 阿里云开发者社区 搜索 Codex 相关话题交流。 祝你编码愉快,效率翻倍!
3806 22
|
19天前
|
Linux API iOS开发
【DSH】DeepSeek Harness新手保姆教程(下载+安装+配置+使用,2026最新实测)
DeepSeek Harness(dsh)是DeepSeek AI开源的智能体框架,秉持“一切皆插件”理念,支持读文件、改代码、跑命令、处理表格、联网搜索等操作。免费开源,兼容Windows/macOS/Linux,提供桌面端与网页端,可灵活安装插件扩展能力。