# #MINNOTES failing first subtask but getting correct answer for second one

Here is my code for optimal denomination problem from div 3 july long challenge.I don’t know why it is giving TLE for first subtask(if it is correct answer for second subtask)

``````#include"bits/stdc++.h"
using namespace std;
#define ll long long int
int main()
{
ios_base::sync_with_stdio(false);
cin.tie(NULL);
ll t;
cin>>t;
while(t--)
{
ll n;
cin>>n;
if(n==1)
{
cout<<"1"<<endl;
continue;
}
vector<ll> prefix(n);
vector<ll> suffix(n);
vector<ll> arr(n);
ll sum=0;
for(ll i=0;i<n;i++)
{
cin>>arr[i];
sum+=arr[i];
}

prefix[0]=arr[0];
suffix[n-1]=arr[n-1];
for(ll i=1;i<n;i++)
{
prefix[i]=__gcd(arr[i],prefix[i-1]);
suffix[n-i-1]=__gcd(arr[n-i-1],suffix[n-i]);

}
ll ans=sum/prefix[n-1];
for(ll i=0;i<n;i++)
{
ll temp=(sum-arr[i])/__gcd((i-1<0?0:(prefix[i-1])),(i+1>=n?0:suffix[i+1]));
ans=min(ans,temp);
}
cout<<ans+1<<endl;

}
return 0;
}`````````

For Testcase

1
1
1

For n = 1, your Code Doesn’t take the input, you directly print the answer.

what is wrong in that?

Hi Abhinav,
Suppose input is this -
2
1
10
2
1 2

When you get the first n = 1 as input. You do not take 10 as input after that. (because of the continue statement).

For the next test case you will get n = 10, and then you will wait for the 10 integers input after that.
This will cause TLE.
Thanks.

wow.That’s a new thing i learnt today.
thanks for clearing that out