package main
import "fmt"
func min (a,b int) int{
if a < b {return a}
return b
}
func minSubArrayLen(target int, n []int) int {
l:=0
sum:=0
m:=1000000
for r := range n {
fmt.Printf("r %d s %d l %d m %d\n", r, sum, l, m)
sum += n[r]
if sum <= target {
continue
}
for {
if sum >= target {
m = min(m, r-l+1)
} else {
break
}
sum -= n[l]
l++
if l > r {
break
}
}
}
return m
}
func main(){
minSubArrayLen(7, []int{2,3,1,2,4,3})
}
cGFja2FnZSBtYWluCmltcG9ydCAiZm10IgpmdW5jIG1pbiAoYSxiIGludCkgaW50ewoJaWYgYSA8IGIge3JldHVybiBhfQoJcmV0dXJuIGIKfQpmdW5jIG1pblN1YkFycmF5TGVuKHRhcmdldCBpbnQsIG4gW11pbnQpIGludCB7CiAgICBsOj0wCiAgICBzdW06PTAKICAgIG06PTEwMDAwMDAKICAgIGZvciByIDo9IHJhbmdlIG4gewogICAgCWZtdC5QcmludGYoInIgJWQgcyAlZCBsICVkIG0gJWRcbiIsIHIsIHN1bSwgbCwgbSkKICAgICAgICBzdW0gKz0gbltyXQogICAgICAgIGlmIHN1bSA8PSB0YXJnZXQgewogICAgICAgICAgICBjb250aW51ZQogICAgICAgIH0KICAgICAgICBmb3IgewogICAgICAgICAgICBpZiBzdW0gPj0gdGFyZ2V0IHsKICAgICAgICAgICAgICAgIG0gPSBtaW4obSwgci1sKzEpCiAgICAgICAgICAgIH0gZWxzZSB7CiAgICAgICAgICAgICAgICBicmVhawogICAgICAgICAgICB9CiAgICAgICAgICAgIHN1bSAtPSBuW2xdCiAgICAgICAgICAgIGwrKwogICAgICAgICAgICBpZiBsID4gciB7CiAgICAgICAgICAgICAgICBicmVhawogICAgICAgICAgICB9CiAgICAgICAgfQogICAgfQoKICAgIHJldHVybiBtCn0KCmZ1bmMgbWFpbigpewoJbWluU3ViQXJyYXlMZW4oNywgW11pbnR7MiwzLDEsMiw0LDN9KQp9