split students by success : <p>i have 5 region that students wants to go. Every region has quota.
For example </p>

<ul>
<li>region A has 3  </li>
<li>region B has 2  </li>
<li>region C has 1  </li>
<li>region D has 2 </li>
<li>region E has 1</li>
</ul>

<p>And i have 9 students. (total quota and student number is same ) and student list is ordered by their success.
My problem is i will send students to region with order like first student needs to go A if quote is not full second will go to B if quote is not full</p>

<p>For the example above i need a string like;
A,B,C,D,E,A,B,D,A
This means</p>

<ul>
<li>1st, 5th and 9th student will go region A</li>
<li>2,7 -> B</li>
<li>c   -> C</li>
<li>4,8 -> D</li>
<li>5   -> E</li>
</ul>

<p>i did already an algorithm for this but it works really slow for 100k student.</p>

<pre><code>public String split(int quotoA, int quotoB, int quotoC, int quotoD, int quotoE) {
    boolean AdidNotGetYet = true, BdidNotGetYet = true, CdidNotGetYet = true, DdidNotGetYet = true, EdidNotGetYet = true;

    StringBuffer list = new StringBuffer();
    while (true) {
        if (quotoA &gt; 0 &amp;&amp; AdidNotGetYet) {
            list.append(",A");
            AdidNotGetYet = false;
            quotoA--;
        } else if (quotoB &gt; 0 &amp;&amp; BdidNotGetYet) {
            list.append(",B");
            BdidNotGetYet = false;
            quotoB--;
        } else if (quotoC &gt; 0 &amp;&amp; CdidNotGetYet) {
            list.append(",C");
            CdidNotGetYet = false;
            quotoC--;
        } else if (quotoD &gt; 0 &amp;&amp; DdidNotGetYet) {
            list.append(",D");
            DdidNotGetYet = false;
            quotoD--;
        } else if (quotoE &gt; 0 &amp;&amp; EdidNotGetYet) {
            list.append(",E");
            EdidNotGetYet = false;
            quotoE--;
        } else {
            AdidNotGetYet = true;
            BdidNotGetYet = true;
            CdidNotGetYet = true;
            DdidNotGetYet = true;
            EdidNotGetYet = true;
        }

        if (quotoA == 0 &amp;&amp; quotoB == 0 &amp;&amp; quotoC == 0 &amp;&amp; quotoD == 0 &amp;&amp; quotoE == 0) {
            break;
        }
    }
    list.deleteCharAt(0);
    return list.toString();
}
</code></pre>
