Rating changes for last rounds are temporarily rolled back. They will be returned soon. ×

Comments
0

D problem was giving TLE when i used unordered_map and when i changed it to map it got accepted. You just have to calculate the minimum number which we have to add to the numbers of the array after which they are divisible by k.

This can be calculated by taking mod.

for example the numbers are 5,1,3,4 and value of k = 3

so for the first element we need to add 1 to get the divisible number

this number can be calculated by taking mod of a[i]-k & k.

-> (k + (a[i]-k)%k)%k;

now similarly for other numbers also we'll calculate in the same way so -> 1,2,0,2 is the required array.

Now Notice that at a time we can select only one element from the above calculated array. It means that when we see 2 or more elements of same type we can't give the same x to them.

It means we have to calculate the next greater number which must be added so that the given number is divisible by k.

the next number can be calculated by multiplying k with the number of times this number has previously occurred, which means we have to maintain the hash table for it.

Your code here...
        long long int n,k;cin>>n>>k;
        long long int a[n],maxm=-1;
        for(int i=0;i<n;i=i+1) scanf("%lld",&a[i]);
        
        map<long long int,long long int>mp;
        vector<long long int>rem;
        
        for(int i=0;i<n;i=i+1)
        {
           long long int val = mod(k-a[i],k);  // taking mod and storing it.
            if(val)rem.push_back(val);
        }
        for(int i=0;i<rem.size();i=i+1)
        {

            long long int val = k*mp[rem[i]] + rem[i];
            mp[rem[i]]++;
            maxm = max(val,maxm);
            
        }
        maxm++;
        printf("%lld\n",maxm);