Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7651663
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T11:33:49+00:00 2026-05-31T11:33:49+00:00

A computer processor is given N tasks to perform (1 ≤ N ≤ 50,000).

  • 0

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

The first line of the input contains the integer N, and the next N lines contain the integers T1 through TN.
Output

Output N lines, the i-th of which contains an integer representing the time elapsed when task i has been processed.

Example

Input:
5
8
1
3
3
8

Output:
22
2
11
12
23

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.

what cud the approach??

This is my code:

#include <iostream>
using namespace std;
int main()
{
int n;
cin>>n;
int a[n];
int total=0;
for(int i=0;i<n;i++)
{cin>>a[i];total+=a[i];}
int b[n];
int j=0;
for(int i=0;i<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<n;i++)
cout<<b[i]<<endl;
system("pause");
return 0;
}    

but this not getting accepted on spoj…

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-31T11:33:50+00:00Added an answer on May 31, 2026 at 11:33 am

    First of all, as Chakradar Raju said, to emulate the whole procedure is not an good way to implement the job for its huge range. And you need to use types that has wider range than int, for example something like long long which is a 64bit int.

    And then try to find a good algorithm to work it out. I’ll provide a method, and wish it work.

    Every time, we consider a task numbered i, and when it comes to the last second of ith task, all the tasks shorter than it has finished. We only need to sum their cost up. For the tasks not shorter than ith task, we assume the ith task takes Ti seconds. The tasks not shorter than it and the ith task itself both work for (Ti – 1) seconds, and for their own (Ti)th of processing, only the tasks before the ith task works. Sum them up, and you’ll get the answer.

    Take the sample as an example:

    For the 1st task, it takes 8 seconds, and the tasks shorter than it has 1 + 3 + 3 = 7 seconds, then it takes 7 seconds for it and the 5th task, so the value is 7 * 2 = 14 seconds. Then there’s no task before ith task, so we only need to add 1 second for the 1st task itself. The result is 7 + 14 + 1 = 22

    Maybe it’s not clear enough, let’s look at the 3rd task, it takes 3 seconds, and only 1 task is shorter than it(the second one which takes 1 second). And all the left tasks take the 3 – 1 = 2 seconds, it’s 4 * 2 = 8 seconds. Finally, there’s only one task left before it, so only it runs the 3rd time. We add it and the 3rd time processing itself. The result is 1 + 8 + 1 + 1 = 11 seconds.

    When coding, you need to remember the sequence number of a task and sort them by their processing time. Then all the tasks short then them are before it. The left job is a linear time processing, and the sort takes O(nlogn) time complexity, which is fast enough to finish the job.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have been given a task to create a Python file that will take
Has anyone run perl script given at http://oreilly.com/pub/h/974#code ? This is a famous one,
As multi-processor and multi-core computers become more and more ubiquitous, is simply firing off
In my Computer Science II class, the professor considers ++,--,*=, etc. to be 2
I need to develop a process that will detect if the users computer has
Is there a cross-platform way to list the processes running on one's computer through
Computer Management -> Services and Applications -> Message Queues How to delete a message
Computer science and programming is a field with a relatively short history but it
Computer Haiku How would you write a program To make them for you
I recently updated my computer to a more powerful one, with a quad-core hyperthreading

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.