Advertisement
fbinnzhivko

05.00 Emergency Repairs

May 4th, 2016
138
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.14 KB | None | 0 0
  1. using System;
  2. public class EmergencyRepairs
  3. {
  4.     public static void Main()
  5.     {
  6.         ulong wall = ulong.Parse(Console.ReadLine());
  7.         int emergencyKits = int.Parse(Console.ReadLine());
  8.         int attacks = int.Parse(Console.ReadLine());
  9.         for (int i = 0; i < attacks; i++)
  10.         {
  11.             int attackedBit = int.Parse(Console.ReadLine());
  12.             wall = wall & ~((ulong)1 << attackedBit);
  13.         }
  14.         for (int i = 0; i < 64; i++)
  15.         {
  16.             ulong bit = (wall >> i) & 1;
  17.             if (bit == 0 && emergencyKits > 0)
  18.             {
  19.                 bool foundHole = false;
  20.                 while (emergencyKits > 0 && i + 1 < 64 && ((wall >> (i + 1) & 1) == 0))
  21.                 {
  22.                     wall = wall | ((ulong)1 << i);
  23.                     i++;
  24.                     emergencyKits--;
  25.                     foundHole = true;
  26.                 }
  27.                 if (foundHole && emergencyKits > 0)
  28.                 {
  29.                     wall = wall | ((ulong)1 << i);
  30.                     emergencyKits--;
  31.                 }
  32.             }
  33.         }
  34.         Console.WriteLine(wall);
  35.     }
  36. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement