THIS IS THE LINK FOR QUESTION:https://practice.geeksforgeeks.org/problems/subarray-with-given-sum/0

#include <iostream>
using namespace std;

int main() {
            long long int s,n,a[10000000000],e,d,l,flag=0,t;
            cin>>t;
            while(t--)
            {   cin>>n>>s;
                e=0;
                flag=0;
                for(long long int i=0;i<n;i++)
                {   cin>>a[i];
                }
                for(long long int j=0;j<n;j++)
                {   e=a[j];
                    for(long long int h=j+1;h<n;h++)
                    {   e+=a[h];
                        if(e==s)
                        {   l=j;
                            d=h;
                            flag=1;
                            break;
                        }
                        else if(e>s)
                        {   flag=2;
                            break;
                        }     

                    }
                    if(flag==1 || flag==2)
                    break;
                }
                if(flag==1)
                cout<<l+1<<" "<<d+1;
                else
                cout<<-1;

                cout<<endl;
            }     
    return 0;
}

Recommended Answers

Do you have enough address space for 10 biilion long long ints (at least 80GB)?

Jump to Post

All 2 Replies

I think perhaps you need to look at the limits of this challenge a little closer. The size of the array(N) is limited to 10⁷. It's the numbers in the array(Aᵢ) that are limited to 10¹⁰.

1 <= T <= 100
1 <= N <= 10⁷
1 <= Aᵢ <= 10¹⁰

Be a part of the DaniWeb community

We're a friendly, industry-focused community of 1.20 million developers, IT pros, digital marketers, and technology enthusiasts learning and sharing knowledge.