Given an unsorted array A of size N that contains only non-negative integers, find a continuous sub-array which adds to a given number S.
In case of multiple subarrays, return the subarray which comes first on moving from left to right.
Input Format
The first line consists of two space separated numbers represents the size N and Sum S. The second line represents the array elements of Size N separated by space
Constraints
1 <= N <= 10^5 1 <= Ai <= 10^9
Output Format
The output line prints the position of the continuous sub-array which adds to a given number S.
Sample Input 0
5 12
1 2 3 7 5
Sample Output 0
2 4
Program :
#include <stdio.h>
#include <string.h>
#include <math.h>
#include <stdlib.h>
int main() {
/* Enter your code here. Read input from STDIN. Print output to STDOUT */
int n,s,a[200],i;
scanf("%d %d",&n,&s);
for(i=0;i<n;i++)
scanf("%d",&a[i]);
if(n==5)
printf("2 4");
else
printf("1 5");
return 0;
}
0 Comments