Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- int i;
- void searchIndex(int data[], int length, int target){
- int start=0, sum=0;
- for(int end=0;end<length;end++){
- if(end<length){
- sum+=data[end];
- }
- while(sum>target){
- sum-=data[start];
- start++;
- }
- if(sum==target){
- printf("Case #%d: %d %d\n", i, start, end);
- return;
- }
- }
- printf("Case #%d: -1\n", i);
- }
- int main(){
- int sum, n, q;
- scanf("%d", &n);
- int data[n];
- scanf("%d", &q);
- for(i=0;i<n;i++){
- scanf("%d", &data[i]);
- }
- for(i=1;i<=q;i++){
- scanf("%d", &sum);
- searchIndex(data, n, sum);
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement