Advertisement
silvana1303

fast food

Sep 20th, 2020
76
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.01 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4.  
  5. namespace advanced
  6. {
  7.     class Program
  8.     {
  9.         static void Main(string[] args)
  10.         {
  11.             int orders = int.Parse(Console.ReadLine());
  12.  
  13.             int[] input = Console.ReadLine().Split().Select(int.Parse).ToArray();
  14.  
  15.             Queue<int> queue = new Queue<int>(input);
  16.  
  17.             int max = queue.Max();
  18.  
  19.             while (queue.Count != 0)
  20.             {
  21.                 if (orders - queue.Peek() >= 0)
  22.                 {
  23.                     orders -= queue.Dequeue();
  24.                 }
  25.                 else
  26.                 {
  27.                     break;
  28.                 }
  29.                
  30.             }
  31.  
  32.             Console.WriteLine(max);
  33.  
  34.             if (queue.Count == 0)
  35.             {
  36.                 Console.WriteLine("Orders complete");
  37.             }
  38.             else
  39.             {
  40.                 Console.WriteLine($"Orders left: {string.Join(" ", queue)}");
  41.             }
  42.         }
  43.     }
  44. }
  45.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement