fork(2) download
  1. //
  2. // main.cpp
  3. // IOI Goals
  4. //
  5. // Created by Nishant Dhankhar on 25/07/18.
  6. // Copyright © 2018 Nishant Dhankhar. All rights reserved.
  7. //
  8.  
  9. #ifndef _GLIBCXX_NO_ASSERT
  10. #include <cassert>
  11. #endif
  12. #include <cctype>
  13. #include <cerrno>
  14. #include <cfloat>
  15. #include <ciso646>
  16. #include <climits>
  17. #include <clocale>
  18. #include <cmath>
  19. #include <csetjmp>
  20. #include <csignal>
  21. #include <cstdarg>
  22. #include <cstddef>
  23. #include <cstdio>
  24. #include <cstdlib>
  25. #include <cstring>
  26. #include <ctime>
  27.  
  28. #if __cplusplus >= 201103L
  29. #include <ccomplex>
  30. #include <cfenv>
  31. #include <cinttypes>
  32. #include <cstdbool>
  33. #include <cstdint>
  34. #include <ctgmath>
  35. #include <cwchar>
  36. #include <cwctype>
  37. #endif
  38.  
  39. // C++
  40. #include <algorithm>
  41. #include <bitset>
  42. #include <complex>
  43. #include <deque>
  44. #include <exception>
  45. #include <fstream>
  46. #include <functional>
  47. #include <iomanip>
  48. #include <ios>
  49. #include <iosfwd>
  50. #include <iostream>
  51. #include <istream>
  52. #include <iterator>
  53. #include <limits>
  54. #include <list>
  55. #include <locale>
  56. #include <map>
  57. #include <memory>
  58. #include <new>
  59. #include <numeric>
  60. #include <ostream>
  61. #include <queue>
  62. #include <set>
  63. #include <sstream>
  64. #include <stack>
  65. #include <stdexcept>
  66. #include <streambuf>
  67. #include <string>
  68. #include <typeinfo>
  69. #include <utility>
  70. #include <valarray>
  71. #include <vector>
  72.  
  73. #if __cplusplus >= 201103L
  74. #include <array>
  75. #include <atomic>
  76. #include <chrono>
  77. #include <condition_variable>
  78. #include <forward_list>
  79. #include <future>
  80. #include <initializer_list>
  81. #include <mutex>
  82. #include <random>
  83. #include <ratio>
  84. #include <regex>
  85. #include <scoped_allocator>
  86. #include <system_error>
  87. #include <thread>
  88. #include <tuple>
  89. #include <typeindex>
  90. #include <type_traits>
  91. #include <unordered_map>
  92. #include <unordered_set>
  93. #endif
  94. #include <iostream>
  95. //#include <bits/stdc++.h>
  96. #define FOR(i,k,n) for(int i=k;i<n;i++)
  97. //#define size() strlen()
  98. #define REV(x) reverse(x.begin(),x.end())
  99. //#define ll %l64d
  100. #define co 100005;
  101. using namespace std;
  102. #define fori(i,n) for(int i=0;i<n;i++)
  103. #define mp make_pair
  104. #define SORT(x) sort(x.begin(),x.end())
  105. //vector<int> num;
  106. #define pb push_back
  107. //int compi(char a,char b)
  108. using namespace std;
  109. #define ll long long
  110.  
  111. int main(){
  112. int n,k;
  113. cin>>n>>k;
  114. string s;
  115. cin>>s;
  116. bool arr[30];
  117. for(int i=0;i<n;i++){
  118. if(!arr[(int) (s[i]-'a'+1)]) arr[(int) (s[i]-'a'+1)]=1;
  119. }
  120. int sum=0;
  121. int count=0;
  122. for(int i=1;i<=26&&count<=k;i++){
  123. if(arr[i]) { count++; sum+=i;i++;}
  124. }
  125. if(count<k) cout<<"-1"<<endl;
  126. else cout<<sum<<endl;
  127. return 0;
  128. }
Success #stdin #stdout 0s 4204KB
stdin
5 3
xyabd
stdout
29