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 SecondNature
- {
- public class StartUp
- {
- public static void Main(string[] args)
- {
- var flowers = Console.ReadLine().Split(new[] { ' ', '\t' }, StringSplitOptions.RemoveEmptyEntries)
- .Select(int.Parse).ToList();
- var water = Console.ReadLine().Split(new[] { ' ', '\t' }, StringSplitOptions.RemoveEmptyEntries)
- .Select(int.Parse).Reverse().ToList();
- var secondNature = new List<int>();
- for (var i = 0; i < flowers.Count; i++)
- {
- for (var j = 0; j < water.Count; j++)
- {
- if (water[j] == 0)
- {
- continue;
- }
- if (flowers[i] == water[j])
- {
- secondNature.Add(flowers[i]);
- flowers[i] = 0;
- water[j] = 0;
- break;
- }
- if (flowers[i] < water[j])
- {
- try
- {
- water[j + 1] += water[j] - flowers[i];
- water[j] = 0;
- }
- catch (Exception)
- {
- water[j] -= flowers[i];
- }
- flowers[i] = 0;
- break;
- }
- flowers[i] -= water[j];
- water[j] = 0;
- }
- }
- var flowersCount = flowers.Count(p => p > 0);
- Console.WriteLine(flowersCount > 0
- ? string.Join(" ", flowers.Where(p => p > 0))
- : string.Join(" ", water.Where(p => p > 0)));
- Console.WriteLine(secondNature.Count>0 ? string.Join(" ",secondNature):"None");
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement