vendredi 26 octobre 2018

why am i getting access violation error c++?

i am getting 0xc0000005 error(access violation error), where am i wrong in this code? i couldnt debug this error. please help me.

question is this

Formally, given a wall of infinite height, initially unpainted. There occur N operations, and in ith operation, the wall is painted upto height Hi with color Ci. Suppose in jth operation (j>i) wall is painted upto height Hj with color Cj such that Hj >= Hi, the Cith color on the wall is hidden. At the end of N operations, you have to find the number of distinct colors(>=1) visible on the wall.

#include<iostream>
#include <bits/stdc++.h>
#include <algorithm>
using namespace std;

int main()
{
   int t;
   cin>>t;
   for(int tt= 0;tt<t;tt++)
   {
       int h,c;
       int temp = 0;
       cin>>h>>c;
       int A[h], B[c];
       vector<int> fc;
       for(int i = 0;i<h;i++)
       {
          cin>>A[i];
       }
       for(int j =0;j<h;j++)
       {
           cin>>B[j];
       }
       if(is_sorted(A,A+h))
       {
           return 1;
       }
       if(count(A,A+h,B[0]) == h)
       {
           return 1;
       }


       for(int i = 0;i<h;i++)
       {

          if(A[i]>=temp)
          {
              temp = A[i];

          }
          else
          {
              if(temp == fc[fc.size()-1])
              {
                  fc[fc.size()-1] = B[i];
              }
              else
              {
                  fc.push_back(B[i]);
              }
           }
         }


     }
  }

Aucun commentaire:

Enregistrer un commentaire