fork download
  1. #include <iostream>
  2. #include <cmath>
  3. #include <algorithm>
  4. #include <string>
  5. #include <vector>
  6. #include <deque>
  7. #define ll long long
  8. using namespace std;
  9. int main()
  10. {
  11. bool found = 0 ;
  12. int n , c = 0;
  13. cin >> n;
  14. string s;
  15. vector<ll> v(n) , v1;
  16. cin >> s;
  17. for(int i = 0 ; i < n ; i++)
  18. cin >> v[i];
  19. for(int i = 0 ; i < n ; i++)
  20. {
  21. if(s[i] == 'R')
  22. {
  23. if(s[i + 1] == 'L')
  24. {
  25. int a = v[i] , b = v[i + 1];
  26. found = 1;
  27. v1.push_back(((a + b) / 2) - v[i]);
  28. }
  29. else
  30. continue;
  31. }
  32. else
  33. continue;
  34. }
  35. if(found)
  36. cout << *min_element(v1.begin(), v1.end()) << '\n';
  37. else
  38. cout << -1 << '\n';
  39. }
  40.  
  41.  
Success #stdin #stdout 0.01s 5460KB
stdin
4
RLRL
2 4 6 10
stdout
1