Bellow, I attach my code, can someone tell me why do I get a runtime error?
For input 1 5 1 2 1 3 1 the correct answer is 2. This example works, but when I put this algorithm to the checker I get "Run time error"
#include <bits/stdc++.h>
using namespace std;
int main()
{
      int z;
      cin >> z;
      for (int ii = 0; ii < z; ii++)
      {
        int k;
        cin >> k;
        vector <int> p(k,0);
        for (int i = 0; i < k; i++)
        {
            int m;
            cin >> m;
            p[m]++;
        }
        sort(p.begin(),p.end());
        int sm = p[0] + p.size()-1;
              for (int i = 1; i < p.size(); i++)
              {
                      int cm = p[i] + p.size()-i-1;
                      if(cm<sm)sm = cm;
              }
              cout << sm << endl;
      }
}
