Advertisement
asaelr

max_sublist

Feb 20th, 2014
161
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.26 KB | None | 0 0
  1. int f(int a[],int n,int *id,int *len) {
  2.     int min=0,pl=0,sum=0,max=0;
  3.     *id=*len=0;
  4.     for (int i=0;i<n;i++) {
  5.         sum+=a[i];
  6.         if (sum<min) {
  7.             min=sum;
  8.             pl=i+1;
  9.         }
  10.         if (sum-min>max) {
  11.             max=sum-min;
  12.             *id=pl;
  13.             *len=i-pl+1;
  14.         }
  15.     }
  16.     return max;
  17. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement