TLE issue

Правка en2, от _manish_yadav_16, 2024-10-15 18:10:57

can anybody help me, why I am getting TLE in TEST CASE 9 ,even though time complexity of my code is nlog(n). question C of Educational Codeforces Round 170. CODE int main(){ int t; cin>>t; while(t--){ ll n,k;cin>>n>>k; unordered_map<ll,ll>mp; setp; for(int i=0;i<n;i++){ ll x;cin>>x; p.insert(x); mp[x]++; } vectors; for(auto i:p){ s.pb(i); } // cout<<s.size()<<endl; ul ans=mp[s[0]],count=mp[s[0]],crr=1,l=0; for(int i=1;i<s.size();i++){ if(s[i]-s[i-1]==1 && crr<k){ count+=mp[s[i]]; crr++; } else if(s[i]-s[i-1]!=1){ ans=max(ans,count); count=mp[s[i]];crr=1; l=i; } else{ ans=max(ans,count); count-=mp[s[l]]; count+=mp[s[i]]; l++; } } ans=max(ans,count); cout<<ans<<endl;

}
return 0;

}

История

 
 
 
 
Правки
 
 
  Rev. Язык Кто Когда Δ Комментарий
en3 Английский _manish_yadav_16 2024-10-15 18:11:59 889
en2 Английский _manish_yadav_16 2024-10-15 18:10:57 892
en1 Английский _manish_yadav_16 2024-10-15 18:09:35 170 Initial revision (published)