I Read all about the reasons for this error(SIGABRT) -> made this program using arrays and that gave me SIGSEGV. Please show me where have I asked for some memory which compiler cannot allocate or narrow it down to exact problem and where it resides??
Constraints are described below, and I've used long long int
- 1 ≤ T ≤ 100
- 1 ≤ N, K ≤ 100,000
- 1 ≤ sum of K over all test cases ≤ 100,000
- 1 ≤ Ai, Di ≤ 1,000,000 for each valid i
- 1 ≤ Bi ≤ C for each valid i
Bi+1 < Bi for each valid i
#include <bits/stdc++.h> using namespace std; typedef long long int ll; int main() { ll T; cin>>T; while(T--){ ll N,K; cin>>N>>K; vector<ll> A(N,0); vector<ll> D(N,0); vector<ll> B(N,0); for(ll i=0; i<N ; i++){ // O(N) cin>>A[i]; } for(ll i=0; i<N ; i++){ // O(N) cin>>D[i]; } for(ll i=0; i<K ; i++){ // O(K) cin>>B[i]; } ll vect_size=0; for(ll i=0; i<N ; i++) // O(N) vect_size += D[i] ; //cout<<vect_size<<endl; vector<ll> cards(vect_size,0); ll sum=0; for(ll i=0; i<N ; i++){ for(ll j=0; j<D[i] ; j++){ cards[ sum+j ] = A[i] ; } sum+=D[i]; } //sort(cards, cards+vect_size ); // O(N.logN) :: N = vect_size sort(cards.begin(), cards.end()); //----------------------game-begins-now----------------------------------------- ll left_lim=0; ll right_lim=vect_size-1; ll cur_size=vect_size; for(ll i=0; i<K; i++){ if( i%2==0 ){ left_lim += cur_size-B[i] ; cur_size = B[i]; } else{ right_lim -= cur_size-B[i]; cur_size = B[i]; } } sum=0; for(ll i=left_lim; i<=right_lim; i++) sum += cards[i]; cout<<sum<<"\n"; } return 0;
}