Source Code
#include <bits/stdc++.h>
#define ll long long
#define all(x) x.begin(),x.end()
#define answer(x) cout << (x ? "YES\n" : "NO\n")
#define test ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); int T; cin >> T; while(T--)
#define go ios::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define F first
#define S second
using namespace std;

const int N = 200100;
ll n, d, a[N];
vector<int> v; 


int main()
{
	int ans = 0;

	cin >> n >> d;
	for(int i=1 ; i<=n;i ++) cin >> a[i];  

	v.push_back(0); 
	for(int i=1 ; i<=n;i++) if(a[i] != d)
		v.push_back(i); 
	v.push_back(n + 1); 
	
	
	int n = v.size();
	for(int i=1 ; i<n ; i++)
		ans = max(ans, v[i] - v[i-1] - 1);
	

	if(d && ans && (ans % 2 == 0))
		ans --;

	cout << ans;
}
Copy
Legendary MuhammedAlajam
GNU G++17
3 ms
848 KB
Wrong Answer