https://codeforces.com/contest/1011

A

 1 #include <bits/stdc++.h>
 2 using namespace std;
 3 int n,k,i,j,p,r,a[179];
 4 string s;
 5 int main(){
 6     for(cin>>n>>k>>s;i<n;i++)a[i]=s[i]-'a'+1;
 7     sort(a,a+n);
 8     for(i=0,p=-1;i<n&&j<k;i++){
 9         if(p+1<a[i])r+=a[i],j++,p=a[i];
10     }
11     cout<<(j==k?r:-1);
12 }
View Code

相关文章:

  • 2021-08-12
  • 2021-04-24
  • 2021-12-04
  • 2021-11-19
  • 2021-04-27
  • 2021-08-14
  • 2021-08-20
猜你喜欢
  • 2021-07-27
  • 2021-05-18
  • 2021-08-18
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-11-17
相关资源
相似解决方案