In the time of code submission I got RE(SIGSEGV) error. My code is:
#include <bits/stdc++.h>
using namespace std;
int main()
{
    int T,val,v;
    int min = INT_MAX;
    int N,M;
    cin >> T;
    while(T--){
        cin >> N >> M;
        vector<int> vec(M+1,0);
        vector<int> arr1;
        for(int i=0;i<N;i++){
            cin >> v;
            arr1.push_back(v);
        }
        for(int j=0;j<N;j++){
            cin >> val;
            vec[arr1[j]]+=val;
        }
        for(int i=1;i<=M;i++){
            if((vec[arr1[i]])<min && (vec[arr1[i]])!=0){
                min = vec[arr1[i]];
            }
        }
        cout << " box: "<<endl;
        for(int a=0;a<vec.size();a++){
            cout << vec[a] << " ";
        }
        cout << endl;
        cout << min << endl;
        vec.clear();
        arr1.clear();
    }   
    return 0;
}
Problem link: https://www.codechef.com/MARCH20B/problems/CHPINTU . Can anyone tell me why is this happening? How can I overcome this problem? Thank you.
 
    