|
|
back to boardwhy runtime error (non zero exit code) in test 3!!! getting runtime error in this code!! pls help me here is my code!!! #include<iostream> #include<vector> #include<algorithm> using namespace std; main() { long long int i,N,j,l; vector<long long int>k,cp; cin >> N; k.resize(N); for(i=0;i<N;i++) cin >> k[i]; cp.resize(N); cp=k; vector<int>ans; sort(cp.begin(),cp.end()); ans.resize(cp[N-1]+1); for(l=1,j=0;l<(cp[N-1]+1);l+=(++j)) ans[l]=1; for(i=0;i<N;i++) cout << ans[k[i]] << " "; return 0; } Edited by author 16.12.2015 14:03 Edited by author 16.12.2015 14:05 Re: why runtime error (non zero exit code) in test 3!!! 1) Any reason to use std::sort() instead of std::maximum_element() to find maximum element? 2) > ans.resize(cp[N-1]+1); What maximum value of "cp[N-1]+1" is? Isn't it 2^31-1? |
|
|