Advertisement
vishwajeet7381

https://codedrills.io/contests/icpc-amritapuri-2022-qualifier-mock-round/problems/red-and-blue

Mar 16th, 2023
410
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.35 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2.  
  3. #define int long long
  4.  
  5. using namespace std;
  6.  
  7. signed main() {
  8.     int t;
  9.     cin >> t;
  10.  
  11.     while (t--) {
  12.  
  13.         int n;
  14.         cin >> n;
  15.         string s;
  16.         cin >> s;
  17.         vector<int> D;
  18.  
  19.         // taking inputs for the array D
  20.         for (int i = 0; i < n; i++) {
  21.             int temp;
  22.             cin >> temp;
  23.             D.push_back(temp);
  24.         }
  25.  
  26.         // trying to count the min number of spills
  27.         int i = 0;
  28.         int maxSpill = -1;
  29.         int count = 0;
  30.  
  31.         bool possible = true;
  32.  
  33.         while (i < n) {
  34.  
  35.             if (s[i] == 'B') {
  36.  
  37.                 if (maxSpill >= i) {
  38.                     int j = i;
  39.                     while (j <= maxSpill && j < n) {
  40.                         s[j] = 'R';
  41.                         j++;
  42.                     }
  43.                     count++;
  44.                 } else {
  45.                     cout << "-1"
  46.                          << "\n";
  47.                     possible = false;
  48.                     break;
  49.                 }
  50.             }
  51.  
  52.             if (D[i] + i > maxSpill) {
  53.                 maxSpill = D[i] + i;
  54.             }
  55.             i++;
  56.         }
  57.  
  58.         // cout<<"String: "<<s<<"\n";
  59.  
  60.         if (possible) {
  61.             cout << count << "\n";
  62.         } else {
  63.             continue;
  64.         }
  65.     }
  66.  
  67.     return 0;
  68. }
  69.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement