Solving System of Equations (Re-posted from StackOverflow as suggested)

I have the following problem.

The functions $f(x),g(x)$ are defined as
$$
f(x) = \begin{cases} f_1(x) &amp; 0 \leq x \leq 10, \\ f_2(x) &amp; 10 &lt; x \leq 20, \\ 0 &amp; \text{otherwise}, \end{cases} \qquad
g(x) = \begin{cases} g_1(x) &amp; 0 \leq x \leq 5, \\ g_2(x) &amp; 5 &lt; x \leq 20, \\ 0 &amp; \text{otherwise}, \end{cases}
$$
In addition, we require the constraints
$$
\int_0^{20} f(x) dx \geq K, \quad \int_0^{20} g(x) dx \geq Q, \quad f(x)+g(x) \leq R \text{ for all $x$}.
$$
where $K,Q,R$ are parameters.

I assume there is quite some elaborate theory behind it, and was wondering if anybody could point me in the right direction to devise an algorithm that can generate $f_1(x), f_2(x), g_1(x), g_2(x)$?

I would like to add that for a given $K$ and $Q$, the interest is to keep $R$ as low as possible.
Let $X$ be a random variable distributed uniformly over $[0,20]$. Your constraints imply
$$ \mathbb{E}[f(X)] \geq \frac{K}{20}, \qquad \mathbb{E}[g(X)] \geq \frac{Q}{20}. $$
We conclude that
$$ \mathbb{E}[f(X)+g(X)] \geq \frac{K+Q}{20}, $$
and so there is some point $x \in [0,20]$ such that $f(x) + g(x) \geq (K+Q)/20$. In particular, $R \geq (K+Q)/20$. This bound is tight, as shown by the functions
$$ f(x) = \frac{K}{20} \mathbf{1}_{x \in [0,20]}, \qquad g(x) = \frac{Q}{20} \mathbf{1}_{x \in [0,20]}. $$