If i understand correctly, the requirement is to write a scheduler.
You can refer to O'REilly 's understanding the linux kernel.

Best Regards
Ashish Goel
"Think positive and find fuel in failure"
+919985813081
+919966006652


On Sun, Mar 20, 2011 at 3:54 PM, Akshata Sharma
<[email protected]>wrote:

> I tried to solve this problem
> https://www.spoj.pl/problems/RRSCHED/
>
> I am getting TLE!! How can I improve my code??
>
> #include<iostream>
> #include<stdio.h>
>
> using namespace std;
>
> struct process
> {
> long time;
> int finished;
> long elapsed_time;
> };
>
> int main()
> {
> long n,sum=0;
> cin>>n;
> struct process prss[50000];
> for(long i=0;i<n;i++)
> {
>         scanf("%ld",&prss[i].time);
>         prss[i].finished=0;
>         sum+=prss[i].time;
> }
> long index=0;
>  for(long k=1;k<=sum;k++)
> {
>   while(prss[index].finished==1)
>   index++;
>
>   prss[index].time--;
>
>   if(prss[index].time==0)
>   {
>    prss[index].finished=1;
>    prss[index].elapsed_time=k;
>   }
>
>   index++;
>   if(index==n)
>   index=0;
> }
>
> for(long i=0;i<n;i++)
> printf("%ld\n",prss[i].elapsed_time);
> return 0;
> }
>
>
>  --
> You received this message because you are subscribed to the Google Groups
> "Algorithm Geeks" group.
> To post to this group, send email to [email protected].
> To unsubscribe from this group, send email to
> [email protected].
> For more options, visit this group at
> http://groups.google.com/group/algogeeks?hl=en.
>

-- 
You received this message because you are subscribed to the Google Groups 
"Algorithm Geeks" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/algogeeks?hl=en.

Reply via email to