Time-dependent analysis of B0 → KS0 π-π+γ decays and studies of the K+π-π+ system in B+ →k+π-π+γ decays