pub fn find_max_sum_subarray_dc<T: Ord + Copy + Default + Add<Output = T>>(src: &[T]) -> (Option<&[T]>, T) {
    if src.len() == 1 {
        if src[0] >= T::default() {
            return (Some(src), src[0]);
        }
        return (None, T::default());
    }
    let mid = src.len() / 2;
    let l = find_max_sum_subarray_dc(&src[0..mid]);
    let r = find_max_sum_subarray_dc(&src[mid..]);
    let c = find_max_sum_cross_subarray(src, mid);

    [l, r, c]
        .iter()
        .max_by(|(x, x_sum), (y, y_sum)| {
            x_sum.cmp(y_sum).then_with(|| {
                // if they have same sum, find longest sub-array
                let x = x.map(|a| a.len());
                let y = y.map(|a| a.len());
                x.cmp(&y)
            })
        })
        .copied()
        .unwrap_or((None, T::default()))
}
/// Divide and conquer implementation. O(n*log n)
///
/// Finds maximum sum sub-array. If there are several subarrays with maximum sum, then returns the
/// longest. If there are no matching sub-arrays, returns 0. By saying "no matching", I mean all the
/// values are less than `T::default()`. Some implementations can still work then, comparing array
/// elements with a kind of `T::MIN`. However, I decided to make a more generic approach to that.
///
/// Clone instead of copy is more preferable for real life generic solutions, but
/// it makes it harder to implement.
Divide and conquer implementation. O(n*log n)
Finds maximum sum sub-array. If there are several subarrays with maximum sum, then returns the
longest. If there are no matching sub-arrays, returns 0. By saying "no matching", I mean all the
values are less than `T::default()`. Some implementations can still work then, comparing array
elements with a kind of `T::MIN`. However, I decided to make a more generic approach to that.

Clone instead of copy is more preferable for real life generic solutions, but
it makes it harder to implement.
Divide and conquer implementation . O ( n * log n ) Finds maximum sum sub - array . If there are several subarrays with maximum sum then returns the longest . If there are no matching sub - arrays returns 0 . By saying " no matching " I mean all the values are less than ` T :: default () ` . Some implementations can still work then comparing array elements with a kind of ` T :: MIN ` . However I decided to make a more generic approach to that . Clone instead of copy is more preferable for real life generic solutions but it makes it harder to implement .
pub fn find_max_sum_subarray_dc<T: Ord + Copy + Default + Add<Output = T>>(src: &[T]) -> (Option<&[T]>, T) {
    if src.len() == 1 {
        if src[0] >= T::default() {
            return (Some(src), src[0]);
        }
        return (None, T::default());
    }
    let mid = src.len() / 2;
    let l = find_max_sum_subarray_dc(&src[0..mid]);
    let r = find_max_sum_subarray_dc(&src[mid..]);
    let c = find_max_sum_cross_subarray(src, mid);
    [l, r, c]
        .iter()
        .max_by(|(x, x_sum), (y, y_sum)| {
            x_sum.cmp(y_sum).then_with(|| {
                // if they have same sum, find longest sub-array
                let x = x.map(|a| a.len());
                let y = y.map(|a| a.len());
                x.cmp(&y)
            })
        })
        .copied()
        .unwrap_or((None, T::default()))
}
pub fn find_max_sum_subarray_dc < T : Ord + Copy + Default + Add < Output = T > > ( src : & [ T ] ) -> ( Option < & [ T ] > , T ) { if src . len ( ) == 1 { if src [ 0 ] >= T :: default ( ) { return ( Some ( src ) , src [ 0 ] ) ; } return ( None , T :: default ( ) ) ; } let mid = src . len ( ) / 2 ; let l = find_max_sum_subarray_dc ( & src [ 0 .. mid ] ) ; let r = find_max_sum_subarray_dc ( & src [ mid .. ] ) ; let c = find_max_sum_cross_subarray ( src , mid ) ; [ l , r , c ] . iter ( ) . max_by ( | ( x , x_sum ) , ( y , y_sum ) | { x_sum . cmp ( y_sum ) . then_with ( | | { // if they have same sum, find longest sub-array let x = x . map ( | a | a . len ( ) ) ; let y = y . map ( | a | a . len ( ) ) ; x . cmp ( & y ) } ) } ) . copied ( ) . unwrap_or ( ( None , T :: default ( ) ) ) }
Divide and conquer implementation.
Divide and conquer implementation .
src
&[T]
src
&[T]