Non decreasing subsequence

can anyone pls tell why am i getting Runtime Error(SIGABRT) error in the below code.

//#include <bits/stdc++.h>
#include <iostream>
#include <vector>
#include<set>
#include<algorithm>
#include<map>
using namespace std;
typedef int ll;

int find(vector<int>& v, int l, int r, int key)
{
    int ans = l+1;
    while(l<=r){
        int m = (l + r)/2;
        if(v[m] > key){
            ans = m;
            r = m-1;
        }
        else{
            l = m+1;
        }
    }
 
    return ans;
}
 
int fun(vector<ll>& v)
{
    if (v.size() == 0)
        return 0;
 
    vector<ll> xxx(v.size(), 0);
    int lll = 1; 
 
    xxx[0] = v[0];
    for (int i = 1; i < v.size(); i++) {

        if (v[i] < xxx[0])
            xxx[0] = v[i];
        else if (v[i] >= xxx[lll - 1])
            xxx[lll++] = v[i];
        else
            xxx[find(xxx, 0, lll - 1, v[i])] = v[i];
    }
 
    return lll;
}

int main() {
    int t = 1;
    cin>>t;
    
    while(t--){
        ll n,K;
        cin>>n>>K;
        vector<ll> v;
        set<ll> sss;
        map<ll,ll> mp;
        for(int i=0;i<n;i++){
            int x;
            cin>>x;
            if(sss.find(x)==sss.end()){
                v.push_back(x);
                sss.insert(x);
            }
            mp[x]++;
        }
        
        int sz = v.size();
        sort(v.begin(),v.end());
        
        
        vector<ll> ans = vector<ll>();
        for(int i=0;i<sz;i++){
            for(int j=i;j<sz;j++){
                vector<ll> temp(n);
                int idx = 0;
                for(int k=i;k<=j;k++){
                    int x = mp[v[k]];
                    while(x > 0){
                        x--;
                        temp[idx++] = v[k];
                    }
                }
                for(int k=sz;k>j;k--){
                    int x = mp[v[k]];
                    while(x > 0){
                        x--;
                        temp[idx++] = v[k];
                    } 
                }
                for(int k=i-1;k>=0;k--){
                    int x = mp[v[k]];
                    while(x > 0){
                        x--;
                        temp[idx++] = v[k];
                    } 
                }
                int check = fun(temp);
                
                if(check == K){
                    
                    if(ans.size()==0){
                        for(int i=0;i<temp.size();i++){
                            ans.push_back(temp[i]);
                        }
                    }
                    else{
                        int sm = 0;
                        for(int k=0;k<temp.size();k++){
                            if(ans[k] < temp[k]){
                                break;
                            }
                            if(temp[k] < ans[k]){
                                sm = 1;
                                break;
                            }
                        }
                        if(sm){
                            ans = temp;
                        }
                    }
                }
            }
        }
        if(ans.size() == 0){
            cout<<-1<<endl;
        }
        else{
            for(int i=0;i<n;i++){
                cout<<ans[i]<<" ";
            }
            cout<<endl;
        }
    }
}

Assuming you are referring to this Problem - out-of-bounds access on sample test input:

[simon@simon-laptop][19:09:54]
[~/devel/hackerrank/otherpeoples]>./compile-latest-cpp.sh         
Compiling macci-DECSUBK.cpp
Executing command:
  g++ -std=c++17 macci-DECSUBK.cpp -O3 -g3 -Wall -Wextra -Wconversion -DONLINE_JUDGE -D_GLIBCXX_DEBUG    -fsanitize=undefined -ftrapv
macci-DECSUBK.cpp: In function ‘int fun(std::__debug::vector<int>&)’:
macci-DECSUBK.cpp:36:23: warning: comparison of integer expressions of different signedness: ‘int’ and ‘std::__cxx1998::vector<int, std::allocator<int> >::size_type’ {aka ‘long unsigned int’} [-Wsign-compare]
   36 |     for (int i = 1; i < v.size(); i++) {
      |                     ~~^~~~~~~~~~
macci-DECSUBK.cpp: In function ‘int main()’:
macci-DECSUBK.cpp:69:24: warning: conversion from ‘std::__cxx1998::vector<int, std::allocator<int> >::size_type’ {aka ‘long unsigned int’} to ‘int’ may change value [-Wconversion]
   69 |         int sz = v.size();
      |                  ~~~~~~^~
macci-DECSUBK.cpp:104:38: warning: comparison of integer expressions of different signedness: ‘int’ and ‘std::__cxx1998::vector<int, std::allocator<int> >::size_type’ {aka ‘long unsigned int’} [-Wsign-compare]
  104 |                         for(int i=0;i<temp.size();i++){
      |                                     ~^~~~~~~~~~~~
macci-DECSUBK.cpp:110:38: warning: comparison of integer expressions of different signedness: ‘int’ and ‘std::__cxx1998::vector<int, std::allocator<int> >::size_type’ {aka ‘long unsigned int’} [-Wsign-compare]
  110 |                         for(int k=0;k<temp.size();k++){
      |                                     ~^~~~~~~~~~~~
Successful
[simon@simon-laptop][19:10:21]
[~/devel/hackerrank/otherpeoples]>echo "4
3 1
2 1 3
3 2
2 1 3
3 3
2 1 3
3 1
2 2 3
" | ./a.out
/usr/include/c++/9/debug/vector:427:
In function:
    std::__debug::vector<_Tp, _Allocator>::reference 
    std::__debug::vector<_Tp, 
    _Allocator>::operator[](std::__debug::vector<_Tp, 
    _Allocator>::size_type) [with _Tp = int; _Allocator = 
    std::allocator<int>; std::__debug::vector<_Tp, _Allocator>::reference = 
    int&; std::__debug::vector<_Tp, _Allocator>::size_type = long unsigned 
    int]

Error: attempt to subscript container with out-of-bounds index 3, but 
container only holds 3 elements.

Objects involved in the operation:
    sequence "this" @ 0x0x7fff9d82db60 {
      type = std::__debug::vector<int, std::allocator<int> >;
    }
Aborted (core dumped)