Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Linq;
- namespace ConsoleApp5
- {
- class Program
- {
- static void Main(string[] args)
- {
- List<int> passengers = Console.ReadLine().Split().Select(int.Parse).ToList();
- int maxCapacity = int.Parse(Console.ReadLine());
- while (true)
- {
- string[] input = Console.ReadLine().Split().ToArray();
- if (input[0] == "end")
- {
- Console.WriteLine(string.Join(" ", passengers));
- return;
- }
- else if (input[0] == "Add")
- {
- passengers.Add(int.Parse(input[1]));
- }
- else
- {
- for (int i = 0; i < passengers.Count; i++)
- {
- if (passengers[i] + int.Parse(input[0]) <= maxCapacity)
- {
- int temp = passengers[i];
- passengers.Insert(i, int.Parse(input[0])+temp);
- passengers.RemoveAt(i + 1);
- break;
- }
- }
- }
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement