Help me in solving DSAAGP16 problem

My issue

showing failed on a hidden test case

My code

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

int main() {
	// your code goes here
	int n;
	cin>>n;
	int arr[n];
	for(int i=0; i<n; i++)
	{
	    cin>>arr[i];
	}
	int t;
	cin>>t;
	while(t--)
	{
	    int a,b;
	    cin>>a>>b;
	    int sum=0,c=0;
	    for(int i=0; i<n; i++)
	    {
	        if(arr[i]==a||i>c)
	        {
	            sum=sum+arr[i];
	            if(arr[i]==b){
	                break;
	            }
	        }
	        else
	        c++;
	    }
	    cout<<sum<<endl;
	}

}

Learning course: Data Structures and Algorithms
Problem Link: https://www.codechef.com/learn/course/dsa-detailed/DSAAG03/problems/DSAAGP16