Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<bits/stdc++.h>
- using namespace std;
- typedef long long int ll;
- typedef unsigned long long int ull;
- typedef vector<int> vi;
- typedef vector<ll> vll;
- typedef vector<vi> vvi;
- typedef pair<int,int > pii;
- typedef vector< pii > vpii;
- typedef set<int> sti;
- #define sc scanf
- #define pf printf
- #define sci(n) scanf("%d",&n)
- #define scl(n) scanf("%lld",&n)
- #define scf(n) scanf("%lf",&n)
- #define scs(s) scanf("%s",s)
- #define pfi(n) printf("%d",n)
- #define pfl(n) printf("%lld",n)
- #define pff(n) cout<<n
- #define line printf("\n")
- #define spc printf(" ")
- #define loop(i,x,y) for(int i=int(x); i<=int(y); i++)
- #define rloop(i,y,x) for(int i=int(y); i>=int(x); i--)
- #define cspf(i) printf("Case %d: ", i)
- #define pb push_back
- #define mp make_pair
- #define ff first
- #define ss second
- #define all(v) v.begin(),v.end()
- #define rall(v) v.rbegin(),v.rend()
- #define read() freopen("input.txt", "r", stdin)
- #define write() freopen("output.txt", "w", stdout)
- /// Constants
- #define eps 1e-9
- #define PI acos(-1.0) // 3.1415926535897932
- vi v;
- int main()
- {
- int n,k;
- sci(n);sci(k);
- int a[200009];
- loop(i,0,n-1){
- sci(a[i]);
- }
- char b[200009];
- scs(b);
- v.pb(a[0]);
- int x=0,cnt=1;
- ll total=0;
- loop(i,1,n-1){
- if(b[i]==b[i-1]){
- v.pb(a[i]);
- }
- else{
- ll temp=0;
- int sz=v.size();
- if(sz>k){
- sort(rall(v));
- loop(j,0,sz-1){
- if(j==k)
- break;
- temp+=v[j];
- }
- }
- else{
- loop(j,0,sz-1){
- temp+=v[j];
- }
- }
- total+=temp;
- v.clear();
- v.pb(a[i]);
- }
- }
- ll temp=0;
- int sz=v.size();
- if(sz>k){
- sort(rall(v));
- loop(j,0,sz-1){
- if(j==k)
- break;
- temp+=v[j];
- }
- }
- else{
- loop(j,0,sz-1){
- temp+=v[j];
- }
- }
- total+=temp;
- v.clear();
- pfl(total);line;
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement