Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<bits/stdc++.h>
- using namespace std;
- #define ll long long
- #define fast()(ios_base::sync_with_stdio(0),cin.tie(NULL));
- #define pi pair<int , int>
- #define mp make_pair
- #define f first
- #define s second
- int main()
- {
- ll t;
- cin>>t;
- while(t--)
- {
- ll n,k,mx=0;
- cin>>n>>k;
- map<ll,ll>mp;
- queue<ll>q;
- ll ara[n+1];
- for(ll i=0; i<n; i++)
- {
- cin>>ara[i];
- }
- sort(ara,ara+n);
- for(ll i=0; i<n; i++)
- {
- ll x=k-(ara[i]%k);
- if(x==k)continue;
- else
- {
- mp[x]++;
- q.push(x);
- }
- }
- while(!q.empty())
- {
- ll x= q.front();
- if(mp[x]>1)
- {
- mp[x]--;
- ll y=mp[x]*k+x;
- mx=max(mx,y);
- mp[y]++;
- q.push(y);
- q.pop();
- }
- else
- {
- mx=max(mx,x);
- q.pop();
- }
- }
- if(mx>0)mx++;
- cout<<mx<<endl;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement