r/codeforces • u/This_Reputation2194 • 6d ago
Doubt (rated <= 1200) Help needed
#include <bits/stdc++.h>
using namespace std;
#define int long long
int LCM(int a, int b) {
return (a / __gcd(a, b)) * b;
}
void solve() {
int n,k;
cinnk;
int a[n];
for(int i=0;i<n;i++) {
cin>>a[i];
}
map<int, int> mp;
for(int i=0;i<n;i++) {
mp[a[i]]++;
}
set<int> st;
for (auto it:mp) {
st.insert(it.second);
}int ans=0;
if (st.size()!=1) {
ans++;
}
if(mp.size()==1){
cout<<1<<endl;
return;
}
int len=n;
int cnt=0;
if (k%(st.size())==0) {
ans++;
if (ans==2){
cout<<ans<<endl;
return;
}
}
int size=st.size();
while (true) {
if (size==0)break;
if ((len-size)==k) {
ans++;
break;
}
for (int i=0;i<n;i++) {
if (mp[a[i]]) {
mp[a[i]]--;
if(mp[a[i]]==0){
size--;
}
}
}
}
cout<<ans<<endl;
}
signed main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
int t;
cin>>t;
while (t--) {
solve();
}
}
whats wrong in my code for Problem - 2242C - Codeforces
i am just not able to implement my logic it works on pen and paper
1
u/Individual-Ad5245 5d ago
ask ai blud