title: round robin implementation
body: <p>A computer processor is given N tasks to perform (1 ≤ N ≤ 50,000). The i-th task requires Ti seconds of processing time (1 ≤ Ti ≤ 1,000,000,000). The processor runs the tasks as follows: each task is run in order, from 1 to N, for 1 second, and then the processor repeats this again starting from task 1. Once a task has been completed, it will not be run in later iterations. Determine, for each task, the total running time elapsed once the task has been completed.
  Input</p>
  
  <p>The first line of the input contains the integer N, and the next N lines contain the integers T1 through TN.
  Output</p>
  
  <p>Output N lines, the i-th of which contains an integer representing the time elapsed when task i has been processed.</p>
  
  <p>Example</p>
  
  <p><strong>Input:</strong>
  5
  8
  1
  3
  3
  8</p>
  
  <p><strong>Output:</strong>
  22
  2
  11
  12
  23</p>
  
  <p>The second task is completed during the first iteration, finishing 2 seconds in. On the third iteration, the third and fourth tasks complete at 11 seconds and 12 seconds, respectively. Finally, on the eighth iteration, the first and last tasks complete at 22 seconds and 23 seconds, respectively.  </p>
  
  <p>what cud the approach??</p>
  
  <p>This is my code:</p>
  
  <pre><code>#include &lt;iostream&gt;
  using namespace std;
  int main()
  {
  int n;
  cin&gt;&gt;n;
  int a[n];
  int total=0;
  for(int i=0;i&lt;n;i++)
  {cin&gt;&gt;a[i];total+=a[i];}
  int b[n];
  int j=0;
  for(int i=0;i&lt;total;i++)
  {
          while(a[j%n]==0) j++;
          a[j%n]-=1;
          if(a[j%n]==0) b[j%n]=i+1; j++;
  }
  for(int i=0;i&lt;n;i++)
  cout&lt;&lt;b[i]&lt;&lt;endl;
  system("pause");
  return 0;
  }    
  </code></pre>
  
  <p>but this not getting accepted on spoj...</p>