My issue
i am counting the number of distinct elements in the array and then then trying to find the multiples of it till it does not exceed the size of the array. But i am getting wrong answer.
My code
#include <bits/stdc++.h>
using namespace std;
#define mod 2e5
int main() {
// your code goes here
long long t;
cin>>t;
while(t--)
{
long long n;
cin>>n;
long long arr[n];
set<long long>s;
for(long long i=0; i<n; i++)
{
cin>>arr[i];
s.insert(arr[i]);
}
long long k=s.size(),ans=k,i=2;
//cout<<k<<" ";
while(ans<=n)
{
ans= k*i*1LL;
i++;
}
cout<<ans-k<<"\n";
}
return 0;
}
Problem Link: Largest K Practice Coding Problem
i did not understand your approach
but you can refer to my code see if that helps you in debugging your code
i named variable randomly sorry if you do not understand what that variable signify
#include <iostream>
#include<bits/stdc++.h>
#include <boost/multiprecision/cpp_int.hpp>
using namespace boost::multiprecision;
#define ll int128_t
#define int long long
#define endl "\n"
#define mod 1000000007
using namespace std;
int power(int a, int b) {
int res = 1;
while (b) {
if (b & 1) {
res = res * a % mod;
}
b >>= 1;
a = a * a % mod;
}
return res;
}
int inv(int a) {
return power(a, mod - 2);
}
int32_t main() {
cin.tie(0)->sync_with_stdio(false);
int t;cin>>t;
while(t--){
int n;cin>>n;
int a[n];
map<int,int>m;
for(int i=0;i<n;i++){cin>>a[i];m[a[i]]++;}
vector<int>v;
for(auto i:m){
v.push_back(i.second);
}
sort(v.begin(),v.end());
int ans=0,sum=0;
int ma=v.size();
for(int i=v.size()-1;i>=0;i--){
sum+=v[i];
int di=sum/(v.size()-i);
ans=max(ans,di*(ma-i));
}
cout<<ans<<endl;
}
cerr << "Time : " << 1000 * ((double)clock()) / CLOCKS_PER_SEC << "ms" << endl;
return 0;
}