SHARE
TWEET

N222

a guest Jan 15th, 2020 49 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include<iostream>
  2. #include<string>
  3.  
  4. using namespace std;
  5.  
  6. int main()
  7. {
  8.     int n, m, l, r;
  9.     cin >> n >>m;
  10.     string a;
  11.     cin >> a;
  12.     for (int i = 0; i < m; i++)
  13.     {
  14.         cin >> l >> r;
  15.         for (int j = l - 1; j < r; j++)
  16.         {
  17.             if (a[j] == '1') a[j] = '0';
  18.             else if (a[j] == '0') a[j] = '1';
  19.         }
  20.     }
  21.     int counter = 0;
  22.     int tempcounter = 0;
  23.     for (int i = 0; i <= n; i++)
  24.     {
  25.         if (a[i] != a[i+1]) tempcounter++;
  26.         else if (a[i] == a[i+1] && counter < tempcounter)
  27.         {
  28.             counter = tempcounter;
  29.         }
  30.         else tempcounter = 0;
  31.     }
  32.     cout << counter;
  33. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top