Advertisement
erfanul007

Untitled

Jan 26th, 2019
154
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.43 KB | None | 0 0
  1. #include<bits/stdc++.h>
  2. using namespace std;
  3.  
  4. typedef long long int ll;
  5. typedef unsigned long long int ull;
  6. typedef vector<int> vi;
  7. typedef vector<ll> vll;
  8. typedef vector<vi> vvi;
  9. typedef pair<int,int > pii;
  10. typedef vector< pii > vpii;
  11. typedef set<int> sti;
  12.  
  13. #define sc scanf
  14. #define pf printf
  15. #define sci(n) scanf("%d",&n)
  16. #define scl(n) scanf("%lld",&n)
  17. #define scf(n) scanf("%lf",&n)
  18. #define scs(s) scanf("%s",s)
  19. #define pfi(n) printf("%d",n)
  20. #define pfl(n) printf("%lld",n)
  21. #define pff(n) cout<<n
  22. #define line printf("\n")
  23. #define spc printf(" ")
  24. #define loop(i,x,y) for(int i=int(x); i<=int(y); i++)
  25. #define rloop(i,y,x) for(int i=int(y); i>=int(x); i--)
  26. #define cspf(i) printf("Case %d: ", i)
  27. #define pb push_back
  28. #define mp make_pair
  29. #define ff first
  30. #define ss second
  31. #define all(v) v.begin(),v.end()
  32. #define rall(v) v.rbegin(),v.rend()
  33. #define read() freopen("input.txt", "r", stdin)
  34. #define write() freopen("output.txt", "w", stdout)
  35. /// Constants
  36. #define eps 1e-9
  37. #define PI acos(-1.0) // 3.1415926535897932
  38.  
  39. vi v;
  40.  
  41. int main()
  42. {
  43. int n,k;
  44. sci(n);sci(k);
  45. int a[200009];
  46. loop(i,0,n-1){
  47. sci(a[i]);
  48. }
  49. char b[200009];
  50. scs(b);
  51. v.pb(a[0]);
  52. int x=0,cnt=1;
  53. ll total=0;
  54. loop(i,1,n-1){
  55. if(b[i]==b[i-1]){
  56. v.pb(a[i]);
  57. }
  58. else{
  59. ll temp=0;
  60. int sz=v.size();
  61. if(sz>k){
  62. sort(rall(v));
  63. loop(j,0,sz-1){
  64. if(j==k)
  65. break;
  66. temp+=v[j];
  67. }
  68. }
  69. else{
  70. loop(j,0,sz-1){
  71. temp+=v[j];
  72. }
  73. }
  74. total+=temp;
  75. v.clear();
  76. v.pb(a[i]);
  77. }
  78. }
  79. ll temp=0;
  80. int sz=v.size();
  81. if(sz>k){
  82. sort(rall(v));
  83. loop(j,0,sz-1){
  84. if(j==k)
  85. break;
  86. temp+=v[j];
  87. }
  88. }
  89. else{
  90. loop(j,0,sz-1){
  91. temp+=v[j];
  92. }
  93. }
  94. total+=temp;
  95. v.clear();
  96. pfl(total);line;
  97. return 0;
  98. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement