Getting wa on codeforces

https://codeforces.com/problemset/problem/988/A

https://codeforces.com/contest/988/submission/88174117

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()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    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])
            {
                ans.push_back(i+1);
                --k;
            }
        }
        ++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
YES
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
completly.

1 Like

good.