Advertisement
amine99

Untitled

Apr 10th, 2018
96
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.11 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3.  
  4. #define _ ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
  5. #define loop(i,b,e) for(auto i=b;i<=e;i++)
  6. #define ALL(x) x.begin(),x.end()
  7. #define SZ(x) x.size()
  8. #define PB push_back
  9. typedef vector<int> VI;
  10.  
  11. int n,a,b,cnt,x,ans;
  12. string s;
  13. VI v;
  14.  
  15. int main() {_
  16.    cin >> n >> a >> b >> s;
  17.    loop(i,0,s.length()) {
  18.       if(s[i] == '.')
  19.          cnt++;
  20.       else if(cnt != 0) {
  21.          v.PB(cnt);
  22.          cnt = 0;
  23.       }
  24.    }
  25.    sort(ALL(v),greater<int>());
  26.    loop(i,0,SZ(v)-1) {
  27.       if(a == 0 && b == 0)
  28.          break;
  29.       if(v[i] % 2 == 0) {
  30.          x = min(v[i]/2,a);
  31.          ans += x;
  32.          a -= x;
  33.  
  34.          x = min(v[i]/2,b);
  35.          ans += x;
  36.          b -= x;
  37.       }
  38.       else {
  39.          x = min(v[i]/2,b);
  40.          ans += x;
  41.          a -= x;
  42.  
  43.          x = min(v[i]/2,a);
  44.          ans += x;
  45.          b -= x;
  46.  
  47.          if(a > b && a >= 1)
  48.             ans++,a--;
  49.          else if(b > a && b >= 1)
  50.             ans++,b--;
  51.          else if(a >= 1 && b >= 1)
  52.             ans++,a--;
  53.       }
  54.    }
  55.    cout << ans;
  56. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement