Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <bits/stdc++.h>
- #define int long long
- using namespace std;
- signed main() {
- int t;
- cin >> t;
- while (t--) {
- int n;
- cin >> n;
- string s;
- cin >> s;
- vector<int> D;
- // taking inputs for the array D
- for (int i = 0; i < n; i++) {
- int temp;
- cin >> temp;
- D.push_back(temp);
- }
- // trying to count the min number of spills
- int i = 0;
- int maxSpill = -1;
- int count = 0;
- bool possible = true;
- while (i < n) {
- if (s[i] == 'B') {
- if (maxSpill >= i) {
- int j = i;
- while (j <= maxSpill && j < n) {
- s[j] = 'R';
- j++;
- }
- count++;
- } else {
- cout << "-1"
- << "\n";
- possible = false;
- break;
- }
- }
- if (D[i] + i > maxSpill) {
- maxSpill = D[i] + i;
- }
- i++;
- }
- // cout<<"String: "<<s<<"\n";
- if (possible) {
- cout << count << "\n";
- } else {
- continue;
- }
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement