Corollary of Riemann Roch theorem I'm studying about Riemann Roch theorem for curves and its consequences (in algebaic gemoetry).
In Hartshorne I've found an exercise equivalent to this assert:

Let $D$ be an effective divisor of a curve $X$ of genus $g$, prove
  that $h^0(D) \leq deg \,D$.

Is easy to prove it in the case of special divisors, but how to prove the assert if $deg \, D \leq 2g-2$?
Thank you for help!
 A: Let $D$ be an effective divisor of degree $d$ on the smooth projective curve $X$ over the algebraically closed field $k$.
If $D=0$ it is clear that $H^0(X,\mathcal O(D))=k $ so that taking dimension we have $l(D)=1$.
If  $\operatorname {deg} D=1$ then $D=1.P$ for some $P\in X$ and $H^0(X,\mathcal O(D))=k $ so that $l(D)=1$,
unless $X=\mathbb P^1$ in which case $l(D)=2$.
And now it is smooth sailing thanks to the exact sequence 

$$0\to H^0(X,\mathcal O(D-P))\to H^0(X,\mathcal O(D)) \to \mathcal O(D)\mid_P \;\cong k\to 0             $$  

where the last non trivial map is evaluation at $P$.
This exact sequence yields $l(D)\leq l(D-P)+1$ from which we deduce by complete induction and the preliminary analysis above that for $\operatorname {deg}(D)\gt 0 $ :  

$$l(D)\leq \operatorname {deg}(D) \quad \operatorname  {if}    X\ncong \mathbb P^1   $$   

and recall that in the remaining case  we have :  

$$ l(D)= \operatorname {deg}(D)+1 \quad \operatorname  {if}    X\cong \mathbb P^1                $$  

Note carefully
The above proof requires essentially only the definitions but not the notion of genus and even less the knowledge of Riemann-Roch.
Notice also that we get (if  $X\ncong \mathbb P^1$  ) $l(D)\leq \operatorname {deg}(D)$ and not the weaker result $l(D)\leq \operatorname {deg}(D)+1$ sometimes found in textbooks .
A: Let $X$ be a smooth projective surface and $D$ an effective divisor on $X$. Then $h^0(D)-1 \leq \mathrm{deg}(D)$.
Let $g$ be the genus of $X$. Since $D$ is effective, $h^0(K_X-D)\leq h^0(K_X) = g$. From this and Riemann-Roch we directly get the claimed inequality $$h^0(D) - 1  = \mathrm{deg}(D)-g+h^0(K_X-D)\leq \mathrm{deg}(D).\quad (*)$$
Addendum, in reaction to Georges Elencwajg's comments:

The inequality $h^0(D)\leq \mathrm{deg}(D)$ holds if and only if $D>0$ or $g\geq 1$.

In fact, it suffices to prove that in $(*)$, equality holds if and only if $D = 0$ or $g = 0$. Apparently, equality in $(*)$ is equivalent to $h^0(K_X-D) = g$.
If $g = 0$ or $D = 0$, then this equality is easy to see.
The other way around suppose $g>0$ and $D>0$.
Then $h^0(\mathcal{O}_X(K_X)\otimes\mathcal{O}_D)> 0$.
Thus, from the long exact sequence associated with the exact sequence $$0\to\mathcal{O}_X(K_X-D)\to\mathcal{O}_X(K_X)\to\mathcal{O}_X(K_X)\otimes\mathcal{O}_D\to 0$$ we get $h^0(K_X-D) < h^0(K_X) = g$.
(This now makes a complete solution to Hartshorne's exercise IV 1.5.)
