Friday, November 3, 2017

876B B. Divisiblity of Differences Codeforces Problem Solution

http://codeforces.com/problemset/problem/876/B

#include<bits/stdc++.h>

using namespace std;


int main()
{
    int a,k,m,n;
    cin>>a>>k>>m;
    int A[a];
    int B[a];
    for(int i=0;i<a;i++)
    {
        cin>>A[i];
        B[i]=A[i]%m;
    }
    sort(B,B+a);
    int count=0;
    for(int i=0;i<a-1;i++){
            if(count+1==k)
            {

                break;
            }
    if(B[i]==B[i+1])
    {
        count++;
        n=B[i];
    }
    if(B[i]!=B[i+1])
    {
        count=0;
    }
    }
    if(count+1!=k)
    {
        cout<<"No"<<endl;
    }
    else
    {
        int rount=0;
        cout<<"Yes"<<endl;
        for(int j=0;j<a;j++)
        {
            if((A[j]%m)==n){
                    rount++;
            if(rount==k)
            {
                cout<<A[j]<<endl;
                break;
            }
            else{
            cout<<A[j]<<" ";
            }
            }
        }
    }
    return 0;
}

No comments:

Post a Comment