#include <iostream>
using namespace std;
int main() {
    int n,k;
    cin>>n>>k;
    int a[n];
    for(int i=0;i<n;i++){
        cin>>a[i];
    }
    int sum=a[0],start=0,i;
    for(i=1;i<=n;i++){
        while(sum>k and start<i-1){
            sum-=a[start];
            start++;
        }
        if(sum==k)
            break;
        if(i<n){
            sum+=a[i];
        }
    }
    if(i-1==n){
        cout<<"Subarray not found\n";
    }
    else{
        cout<<start<<" "<<i-1;
    }
    return 0;
}

Embed on website

To embed this program on your website, copy the following code and paste it into your website's HTML: