Please help me why this code not getting ac

this is the question of last third question LSU LSU
i don’t know why my code getting ac my core logic is just see which one to take for minimum

void coderaryan()
{
    // executing code from here
    int t;
    cin >> t;
    while (t--)
    {
        int n, v;
        cin >> n >> v;
        string s;
        cin >> s;
        set<char> st;
        set<char> sat;
        for (auto i : s)
        {
            sat.insert(i);
        }
        int ans = 0;
        for (int i = 0; i < n; i++)
        {
            if (i + 1 < v)
            {
                ans += min(i + 1, v);
            }
            else
            {
                if (st.find(s[i]) != st.end())
                {
                    ans += 0;
                }
                else
                {
                    st.insert(s[i]);
                    ans += v;
                }
            }
        }
        cout << min(ans,sat.size()*v) << endl;
    }
}

It looks like you’re trying to compute the minimum cost of selecting elements from a string while considering unique characters. However, your approach might have some logical inconsistencies
Try restructuring your approach to focus purely on counting unique characters rather than indexing errors.

int n, v;
        cin >> n >> v;
        string s;
        cin >> s;
        
        set<char> unique_chars;
        for (char c : s) {
            unique_chars.insert(c);
        }