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 _03.EnduranceRally
- {
- public class Startup
- {
- public static void Main()
- {
- var drivers = Console.ReadLine().Split(new[] { ' ' }, StringSplitOptions.RemoveEmptyEntries);
- var zones = Console.ReadLine().Split(new[] { ' ' }, StringSplitOptions.RemoveEmptyEntries).Select(decimal.Parse).ToArray();
- var checkpointsIndexes = Console.ReadLine().Split(new[] { ' ' }, StringSplitOptions.RemoveEmptyEntries).Select(int.Parse).ToList();
- foreach (var driver in drivers)
- {
- decimal initialFuel = (decimal)driver[0];
- int position = 0;
- for (int i = 0; i < zones.Length; i++)
- {
- if (checkpointsIndexes.Contains(i))
- {
- initialFuel += zones[i];
- }
- else
- {
- initialFuel -= zones[i];
- }
- if (initialFuel <= 0)
- {
- position = i;
- break;
- }
- }
- if (initialFuel <= 0)
- {
- Console.WriteLine($"{driver} reached {position}");
- }
- else
- {
- Console.WriteLine($"{driver} - fuel left {initialFuel:f2}");
- }
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment