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;
- using System.IO;
- namespace ConsoleApp12
- {
- public class Work
- {
- public string name;
- public int a;
- public int b;
- public Work(string name, int a, int b)
- {
- this.name = name;
- this.a = a;
- this.b = b;
- }
- }
- class Program
- {
- static void Main(string[] args)
- {
- StreamReader str = new StreamReader("input.txt");
- string[] lines = str.ReadToEnd().Split('\n');
- int count = lines.Length;
- LinkedList<Work> works = new LinkedList<Work>();
- for (int i = 0; i < count; i++)
- {
- string name = lines[i].Split(' ')[0];
- int a = int.Parse(lines[i].Split(' ')[1]);
- int b = int.Parse(lines[i].Split(' ')[2]);
- if (i == 0)
- works.AddFirst(new Work(name, a, b));
- else
- {
- var current = works.First;
- for (int j = 0; j < works.Count; j++)
- {
- int t1 = Math.Min(a, current.Value.b);
- int t2 = Math.Min(current.Value.a, b);
- if (t1 < t2)
- {
- works.AddBefore(current, new Work(name, a, b));
- break;
- }
- else
- {
- if (current.Next == null)
- {
- works.AddAfter(current, new Work(name, a, b));
- break;
- }
- current = current.Next;
- }
- }
- }
- }
- int time = works.First.Value.a;
- int endfirst = 0;
- int startsecond = time;
- foreach (Work current in works)
- {
- endfirst += current.a;
- if (endfirst > startsecond)
- {
- time += endfirst - startsecond;
- startsecond = endfirst;
- }
- startsecond += current.b;
- time += current.b;
- Console.Write(current.name + " ");
- }
- Console.WriteLine();
- Console.WriteLine(time);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement