In round 1021 Div 2 Problem C
Why when i implemented the code this way i got WA
void solve(){ int n ; cin >> n ; dequev(n),v2; map<int,int>freq; for(int i=0;i<n;i++) { cin >> v[i]; freq[v[i]]++; if (freq[v[i]]==1) {v2.push_back(v[i]);} if (freq[v[i]]>=4) { YES return; } } sort(v2.begin(),v2.end());
int c = 0, p = -1e9;
for (int x : v2) {
if (x != p + 1) c = 0;
if (freq[x] >= 2 && ++c >= 2) {cout<<"YES\n"; return;}
p = x;
}
NO}
but when i changed the way of filtering duplicates into v2 vector to this way i got Accepted
no changes only the way of filtering duplicates changed
void solve(){ int n ; cin >> n ; dequev(n),v2; map<int,int>freq; for(int i=0;i<n;i++) { cin >> v[i]; freq[v[i]]++; } for (auto & p: freq) { if (p.second>3) { YES return; } v2.push_back(p.first); } sort(v2.begin(),v2.end());
int c = 0, p = -1e9;
for (int x : v2) {
if (x != p + 1) c = 0;
if (freq[x] >= 2 && ++c >= 2) {cout<<"YES\n"; return;}
p = x;
}
NO}








