Advertisement
Guest User

Untitled

a guest
Oct 16th, 2019
122
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.56 KB | None | 0 0
  1. #include <stdio.h>
  2.  
  3. const int min(const int a, const int b);
  4. const int min(const int a, const int b) { return (b < a) ? b : a; }
  5.  
  6. int main() {
  7.     int n_friends, mood;
  8.     char friends [200001];
  9.     scanf("%d %d\n%200000s", &n_friends, &mood, friends);
  10.    
  11.     int min_mood = mood;
  12.    
  13.     for (int i = 0; i < n_friends - 1; i++) {
  14.         if (friends[i] == 'A') { mood++; min_mood = min(min_mood, mood); }
  15.         else if (friends[i] == 'C') { mood--; min_mood = min(min_mood, mood); }
  16.     }
  17.    
  18.     printf("%d", -min(0, min_mood));
  19.     return 0;
  20. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement