Getting wa on codeforces

help me to solve this tell me where i’m wrong
but sample tests have passed

try for this test case
6 4
1 9 3 2 5 8

My code:

#include <bits/stdc++.h>

using namespace std;

int main()
    unordered_map <int, int> m;
    int n, k, x;
    cin >> n >> k;
    vector <int> ans(0);
    for (int i = 0; i < n; ++i)
        cin >> x;
        if (k)
            if (!m[x])
    if (!k) 
        cout << "YES\n";
        for (int i : ans) cout << i << " ";
    else cout << "NO\n";

Should be self explanatory.

1 Like

The answer is no

can u tell why did u used map instead of an array

You can use a frequency array but I like to use a map because it uses less memory although the contsraints are pretty small for this problem.

ok can u tell me why code is going wrong?

wrong, it should have answer
1 2 3 4
because if we have more elements which are distinct than k values, then we only need to print K values from that distincts.

1 Like

Thanks @prabhat_7 for you help i think i did not read the question

1 Like