Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- namespace Proccesor_Schedualing
- {
- class Program
- {
- static void Main(string[] args)
- {
- string input = Console.ReadLine();
- int colonIndex = input.IndexOf(":");
- int n = int.Parse(input.Substring(colonIndex + 1).Trim());
- var tasks = new List<KeyValuePair<int, Tuple<int,int>>>();
- for (int i = 0; i < n; i++)
- {
- int[] entry = Console.ReadLine().Split(new char[] { ' ', '-' }, StringSplitOptions.RemoveEmptyEntries).Select(int.Parse).ToArray();
- tasks.Add(new KeyValuePair<int, Tuple<int,int>>(entry[0], new Tuple<int,int>(entry[1],i+1)));
- }
- Schedualing(tasks);
- }
- public static void Schedualing(List<KeyValuePair<int, Tuple<int, int>>> task)
- {
- int stepsCount = task.OrderByDescending(x => x.Value.Item1).FirstOrDefault().Value.Item1;
- var sorted = task.OrderByDescending(x => x.Key).ThenByDescending(x=>x.Value.Item1);
- var top = sorted.Take(stepsCount).OrderBy(x=>x.Value.Item1).ToList();
- var result = new List<int>();
- int[] steps = new int[stepsCount];
- int skip = 0;
- for (int i = 0; i < stepsCount; i++)
- {
- var item = top.Skip(skip).Take(1).FirstOrDefault();
- result.Add(item.Key);
- steps[i] = item.Value.Item2;
- skip++;
- }
- Console.WriteLine("Optimal schedule: "+string.Join(" -> ",steps));
- int totalVal = result.Sum();
- Console.WriteLine("Total value: "+totalVal );
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement