Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<bits/stdc++.h>
- using namespace std;
- int subarray(int arr[], int s){
- int max_so_far=arr[0];
- int curr_max=arr[0];
- for(int i=1; i<s; i++)
- {
- curr_max=max(arr[i],curr_max+arr[i]);
- max_so_far=max(max_so_far,curr_max);
- }
- return max_so_far;
- }
- int main()
- {
- int s,arr[100];
- scanf("%d",&s);
- for(int i=0; i<s; i++)
- {
- scanf("%d",&arr[i]);
- }
- printf("%d\n",subarray(arr,s));
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement