Quantcast
Channel: CodeChef Discuss - latest questions
Viewing all articles
Browse latest Browse all 39796

Runtime error

$
0
0

I am getting a runtime error(SIGSEGV) when I run the code on codechef's compiler. Below is my code but when I run this code on my local machine then it is giving me the right outputs. I don't know what is the problem in the code.

include <iostream>

include<limits.h>

include<vector>

using namespace std; vector <int> g; int dif(int m1) { int d=INT_MAX,el,c; vector<int>::iterator r; vector<int>::iterator i; for (i = g.begin(); i != g.end(); ++i) { el=*i; if((m1-el)>=0 && (m1-el)<d) { r=i; d=(m1-el); c=1; } } if(c==1) { m1=d; g.erase(r); }

return m1;

}

int main() { int t,n,m,count,x; cin>>t; for(int i=0;i<t;i++) {="" <br=""/> int y; cin>>n; cin>>m; y=n; int *a=new int[n]; for(int j=0;j<n;j++) {="" cin="">>a[j]; g.push_back(a[j]); } while(m>0 && y!=0) { x=dif(m); m=x; y--; }

    if(m==0)
        cout<<"Yes"<<"\n";
    else
        cout<<"No"<<"\n";
    g.clear();
}
return 0;

}


Viewing all articles
Browse latest Browse all 39796

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>