recursive function get_max(part, length) result(res) implicit none integer::part(*) integer::length,x,y integer::res(2,2),first(2,2),second(2,2) integer::plength integer,parameter::on=1,off=2 if (length.ge.4) then plength = length/2 first = get_max(part(1:plength),plength) second = get_max(part(plength+1:length),length-plength) res(on,on) = MAXVAL((/first(on,off)+second(off,on), & first(on,off)+second(on, on), & first(on, on)+second(off,on)/)) res(on,off) = MAXVAL((/first(on,off)+second(off,off), & first(on,off)+second(on, off), & first(on, on)+second(off,off)/)) res(off,on) = MAXVAL((/first(off,off)+second(off,on), & first(off,off)+second(on, on), & first(off, on)+second(off,on)/)) res(off,off) = MAXVAL((/first(off,off)+second(off,off), & first(off,off)+second(on, off), & first(off, on)+second(off,off)/)) else if(length.eq.3) then res(on,on) = MAX(part(1)+part(3),part(2)) res(on,off) = MAX(part(1),part(2)) res(off,on) = MAX(part(2),part(3)) res(off,off) = part(2) else if(length.eq.2) then res(on,on) = MAX(part(1),part(2)) res(on,off) = part(1) res(off,on) = part(2) res(off,off) = 0 end if end function get_max program main implicit none interface recursive function get_max(part, length) result(res) integer::part(*) integer::length integer::res(2,2) end function get_max end interface integer::N integer::oisisa(2,2) integer::V(1000) read *, N read *, V(1:N) if(N.eq.1) then oisisa=V(1) else oisisa = get_max(V(1:N),N) end if print '(2i5)',oisisa print '(i0)',MAXVAL(oisisa) end program main