I noticed something weird today, so I was solving one problem and I m attaching the question link along with the solution which I used
https://mirror.codeforces.com/contest/1832/problem/C
include<bits/stdc++.h>
define ll long long
using namespace std; void fast_io() { ios::sync_with_stdio(false); cin.tie(0);
cout.tie(0); }
void dowork(ll int n, vector&arr){ if(count(arr.begin(),arr.end(),arr[0])==n){ cout<<1<<endl; return; } for(int i=0;i<arr.size()-1;i++){ if(arr[i]==arr[i+1]){ arr.erase(arr.begin()+i); i--; } } ll int cnt=2; ll int i=1; while(i<=n-2){ if(arr[i]>arr[i-1] && arr[i]>arr[i+1]){ cnt++; } else if(arr[i]<arr[i-1] && arr[i]<arr[i+1]){ cnt++; } i++;
} cout<<cnt<<endl; return;
}
int main(){ fast_io(); int t; cin>>t; while(t--){ ll int n; cin>>n; vectorarr(n); for(int i=0;i<n;i++){ cin>>arr[i]; } dowork(n,arr); } return 0; }
I know that I shoukdnt have used the delete function, since it can take the time complexity to O(N^2) when u delete that element and keep on shifting the remaining elements to the left, but I was tired so I just submitted it, and it got TLE on test 11 in C++ 23 Version, but surprisingly got accepted in C++ 20 Version, can anybody explain why did such thing happen?








It is hard to read without proper formatting.