As explained the problem is solved in linear time by forming a running sum of the $a_i$. Keep track of the minimum sum formed (starting with a zero initial sum). The location of the minimum running sum tells where the leading $X_i$ should be all zeros. After setting the next variable to 1, it doesn't matter how the rest get set. For the sake of specificity we can require the $X_i$ to be increasing.
The formulation would be a bit simpler if, instead of binary $X_i$, we used binary $Y_i = 1-X_i$ (then $Y_i$ are decreasing), but I'll stick to the notation used in the Question. We write:
$$ min \sum_{i=1}^N a_i (1-X_i), \;\;\text{ where } \;\; X_i \in \{0,1\} $$
$$ X_1 \leq X_2 \leq \ldots \leq X_N $$
The discrete binary values for $X_i$ make this a integer linear program (ILP), which are generically hard problems. The particular problem here though is easily solved in time linear with the number of available $X_i$.
A free and open source solver for such problems is lp_solve. For $N=3$ the lp_solve model can be written as a text file in this way, assuming coefficients $a_1 = 0.2, a_2 = -3, a_3 = 4.1$:
min: 0.2*(1 - x1) - 3*(1 - x2) + 4.1*(1 - x3);
x2 - x1 >= 0;
x3 - x2 >= 0;
bin: x1, x2, x3