Advertisement
Rofyda_Elghadban1

Untitled

Mar 14th, 2024
24
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.57 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2. #define ll long long
  3. #define ull unsigned long long
  4. #define pi 3.141592654
  5. #define NUM 1e18
  6. #define Mod 1'000'000'007
  7. #define fixed(n) fixed<<setprecision(n)
  8. #define cin(v) for(auto &i:v) cin >> i ;
  9. #define cout(v) for(auto &i:v) cout << i <<" ";
  10. #define vowel(x) (x=='e'||x=='a'||x=='i'||x=='o'||x=='u')
  11. #define small(x) (x>=97&&x<=122)
  12. #define capital(x) (x>=65&&x<=90)
  13. #define Tolower(s) transform(s.begin(),s.end(),s.begin(),::tolower);
  14. #define Toupper(s) transform(s.begin(),s.end(),s.begin(),::toupper);
  15. #define sz(x) (int)(x.size())
  16. #define all(v) ((v).begin()), ((v).end())
  17. #define allr(v) ((v).rbegin()), ((v).rend())
  18. #define updmax(a,b) a=max(a,b)
  19. #define updmin(a,b) a=min(a,b)
  20. #define ceil(a,b) ((a/b)+(a%b?1:0))
  21. /* asc -> 1 2 3 ,des -> 3 2 1 */
  22.  
  23. /***********************************************************************************/
  24. using namespace std;
  25. void Rofyda_Elghadban(){
  26. #ifndef ONLINE_JUDGE
  27. freopen("input.txt", "r", stdin), freopen("output.txt", "w", stdout);
  28. #endif
  29. ios_base::sync_with_stdio(false), cin.tie(nullptr), cout.tie(nullptr);
  30. }
  31.  
  32.  
  33.  
  34. void solve(){
  35. int n,k,maxi1=INT_MIN,counter1=0,maxi2=INT_MIN,counter2=0;
  36. cin>>n>>k;
  37. string s;
  38. cin>>s;
  39. string t=s;
  40. int temp1=k,temp2=k;
  41. char c1,c2;
  42. /*G*/
  43. for(int i=0;i<n;i++){
  44. temp1=k;
  45. if(s[i]!='G'){
  46. temp1--;
  47. counter1++;
  48. c1=s[i];
  49. }
  50. if(i<n-1){
  51. for(int j=i+1;j<n;i++){
  52. if(s[j]!=c1){
  53. counter1++;
  54. c1=s[j];
  55. }else{
  56. if(temp1>0){
  57. temp1--;
  58. counter1++;
  59. if(c1=='G'){
  60. s[j]=='B';
  61. }else{
  62. s[j]=='G';
  63. }
  64. }else{
  65. break;
  66. }
  67. }
  68. }
  69. }
  70. maxi1=max(maxi1,counter1);
  71. counter1=0;
  72. }
  73. /*B*/
  74. for(int i=0;i<n;i++){
  75. temp2=k;
  76. if(t[i]!='B'){
  77. temp2--;
  78. counter2++;
  79. c2=t[i];
  80. }
  81. if(i<n-1){
  82. for(int j=i+1;j<n;i++){
  83. if(t[j]!=c2){
  84. counter2++;
  85. c2=t[j];
  86. }else{
  87. if(temp2>0){
  88. temp2--;
  89. counter2++;
  90. if(c2=='B'){
  91. t[j]=='G';
  92. }else{
  93. t[j]=='B';
  94. }
  95. }else{
  96. break;
  97. }
  98. }
  99. }
  100. }
  101. maxi2=max(maxi2,counter2);
  102. counter2=0;
  103. }
  104. cout<<max(maxi1,maxi2)<<"\n";
  105. }
  106.  
  107. int main(){
  108. Rofyda_Elghadban();
  109. int t=1;
  110. // cin>>t;
  111. while(t--){
  112. solve();
  113. }
  114. return 0;
  115. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement