Let $A$ be a ring, $X=\operatorname{Spec}A$ and $f: Z \rightarrow X$ a morphism of schemes such that i) $f$ is a homeomorphism of topological spaces and ii) $f^{\#}:\mathcal{O}_X \rightarrow f_* \mathcal{O}_Z$ is a surjective morphism of sheaves.
Question 1: How can we show that $Z$ is an affine scheme?
I am trying to follow the hint of exercise II.3.11(b) in Hartshorne, but i am getting stuck: i can show that $Z$ can be covered by a finite number of $\operatorname{Spec}B_i$ and each $\operatorname{Spec}B_i$ can be covered by finitely many $D(\phi_i(a_{ij}))$, where $a_{ij} \in A$, and $\phi_i: A \rightarrow B_i$ is the ring homomorphism that corresponds to the restriction of $f$ to $\operatorname{Spec}B_i$. Now, if i am to apply exercise II.2.17(b), i would need to show that each of the $Z_{\phi(a_{ij})}$ is affine, where $\phi: A \rightarrow \Gamma(Z,\mathcal{O}_Z)$ is the ring homomorphism of global sections.
Question 2: Any ideas how we can show that $Z_{\phi(a_{ij})}$ is affine?
Question 3: Alternatively, i have been able to show that each $\operatorname{Spec}B_i$ is isomorphic as a scheme with $\operatorname{Spec}(A/I_i)$, where $I_i$ is the kernel of $\phi_i$. Any ideas how to continue for there?