/*  linebreaks2.c  */

/*  A greedy but suboptimal algorithm.  */

#include "linebreaks.h"

void ChooseLineBreaks (int n, int L[], int M, int B[]) {
    int n1 = n - 1;
    int i = 0;
    int thisline = L[0];
    while (i < n1) {
        B[i] = 0;
        if (thisline <= M) {
            i = i + 1;
            thisline = thisline + 1 + L[i];
        }
        else {
            B[i-1] = 1;
            thisline = L[i];
        }
    }
    B[n1] = 0;
    if (thisline > M) {
        B[i - 1] = 1;
    }
}