title: Scheduling Algorithm with limitations
body: <p>Thanks to user3125280, D.W. and Evgeny Kluev the question is updated.</p>
  
  <p>I have a list of webpages and I must download them frequently, each webpage got a different download frequency. Based on this frequency we group the webpages in 5 groups:</p>
  
  <pre><code>Items in group 1 are downloaded once per 1 hour
  items in group 2 once per 2 hours
  items in group 3 once per 4 hours
  items in group 4 once per 12 hours
  items in group 5 once per 24 hours
  </code></pre>
  
  <p>This means, we must download all the group 1 webpages in 1 hour, all the group 2 in 2 hours etc.</p>
  
  <p>I am trying to make an algorithm. As input, I have:</p>
  
  <p>a) <code>DATA_ARR</code> = one array with 5 numbers. Each number represents the number of items in this group.</p>
  
  <p>b) <code>TIME_ARR</code> = one array with 5 numbers (1, 2, 4, 12, 24) representing how often the items will be downloaded.</p>
  
  <p>b) <code>X</code> = the total number of webpages to download per hour. This is calculated using items_in_group/download_frequently and rounded upwards. <code>If we have 15 items in group 5, and 3 items in group 4, this will be 15/24 + 3/12 = 0.875 and rounded is 1.</code></p>
  
  <p>Every hour my program must download at max <code>X</code> sites. I expect the algorithm to output something like:</p>
  
  <pre><code>Hour 1: A1 B0 C4 D5
  Hour 2: A2 B1 C2 D2
  ...
  </code></pre>
  
  <p>A1 = 2nd item of 1st group<br/>
  C0 = 1st item of 3rd group</p>
  
  <p>My algorithm must be as efficient as possible. This means:</p>
  
  <p>a) the pattern must be <strong>extendable</strong> to at least 200+ hours<br/>
  b) <strong>no need to create a repeatable pattern</strong><br/>
  c) spaces are <strong>needed</strong> when possible in order to use the absolute minimum bandwidth<br/>
  d) <strong>never ever download an item more often than the update frequency, no exceptions</strong><br/></p>
  
  <hr>
  
  <p><strong>Example:</strong></p>
  
  <pre><code>group 1: 0 items | once per 1 hour
  group 2: 3 items | once per 2 hours
  group 3: 4 items | once per 4 hours
  group 4: 0 items | once per 12 hours
  group 5: 0 items | once per 24 hours
  </code></pre>
  
  <p>We calculate the number of items we can take per hour: <code>3/2+4/4 = 2.5. We round this upwards and it's 3.</code></p>
  
  <p>Using pencil and paper, we can found the following solution:</p>
  
  <pre><code>Hour 1: B0 C0 B1
  Hour 2: B2 C1 c2
  Hour 3: B0 C3 B1
  Hour 4: B2
  Hour 5: B0 C0 B1
  Hour 6: B2 C1 c2
  Hour 7: B0 C3 B1
  Hour 8: B2
  Hour 9: B0 C0 B1
  Hour 10: B2 C1 c2
  Hour 11: B0 C3 B1
  Hour 12: B2
  Hour 13: B0 C0 B1
  Hour 14: B2 C1 c2
  and continue the above.
  </code></pre>
  
  <p>We take <code>C0</code>, <code>C1</code> <code>C2</code>, and <code>C3</code> once every 4 hours. We also take <code>B0</code>, <code>B1</code> and <code>B2</code> once every 2 hours.</p>
  
  <hr>
  
  <p><strong>Question: Please, explain to me, how to design an algorithm able to download the items, while using the absolute minimum number of downloads?</strong> Brute force is <strong>NOT</strong> a solution and the algorithm must be efficient CPU wise because the number of elements can be huge.</p>
  
  <p>You may read the answer posted here: <a href="https://cs.stackexchange.com/a/19422/12497">https://cs.stackexchange.com/a/19422/12497</a> as well as the answer posted bellow by user3125280.</p>