#include<stdio.h>
int main(){
        //int pet[5]={10,1,19,19,1};
        int pet[5]={10,1,18,20,1};
        int point[5] = {10,20,30,40,50};
        int tmp[5],index=0;
        int i;
        tmp[0]=pet[0];
        for(i=1;i<5;i++){
                tmp[i]= pet[i]+tmp[i-1];
                printf("%d, %d\n",tmp[i],point[i]);
                if(tmp[i]<point[i])
                        index=i+1;
        }
        if(tmp[i-1]<point[i-1])
                printf("Cannot be reached: %d, %d\n",tmp[i-1],point[i-1]);
        else
                printf("Starting at %d is feasible\n",index);
        return 1;
}

How about this, Single traverse, no extra space, the tmp array can be removed 
using a single tmp variable.

I couldn't find an example to counter this one.

-- 
You received this message because you are subscribed to the Google Groups 
"Algorithm Geeks" group.
To view this discussion on the web visit 
https://groups.google.com/d/msg/algogeeks/-/7XY9shwXpyUJ.
To post to this group, send email to algogeeks@googlegroups.com.
To unsubscribe from this group, send email to 
algogeeks+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/algogeeks?hl=en.

Reply via email to