Advertisement
Guest User

6. Вырубка леса

a guest
Jan 27th, 2015
355
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 3.27 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.IO;
  5. using System.Text;
  6. using System.Threading.Tasks;
  7.  
  8. namespace region
  9. {
  10.     class Program
  11.     {
  12.         const ulong inf = 1000000000000000000;
  13.         const string Name = "forest";
  14.         #region Read
  15.         static string[] Split(string s)
  16.         {
  17.             return s.Split(" ".ToCharArray(), StringSplitOptions.RemoveEmptyEntries);
  18.         }
  19.         static int ReadInt()
  20.         {
  21.             return int.Parse(Console.ReadLine());
  22.         }
  23.         static long ReadLong()
  24.         {
  25.             return long.Parse(Console.ReadLine());
  26.         }
  27.         static double ReadDouble()
  28.         {
  29.             return double.Parse(Console.ReadLine());
  30.         }
  31.         static int[] ReadArrayL()
  32.         {
  33.             int l = ReadInt();
  34.             return ReadArray(Split(Console.ReadLine()), l);
  35.         }
  36.         static int[] ReadArray()
  37.         {
  38.             return ReadArray(Split(Console.ReadLine()));
  39.         }
  40.         static int[] ReadArray(int count)
  41.         {
  42.             return ReadArray(Split(Console.ReadLine()), count);
  43.         }
  44.         static int[] ReadArray(string[] args)
  45.         {
  46.             return ReadArray(args, args.Length);
  47.         }
  48.         static int[] ReadArray(string[] args, int count)
  49.         {
  50.             int[] res = new int[count];
  51.             for (int i = 0; i < count; i++)
  52.             {
  53.                 res[i] = int.Parse(args[i]);
  54.             }
  55.             return res;
  56.         }
  57.         #endregion
  58.         #region Init
  59.         static void InitIO(string path)
  60.         {
  61.             Console.SetIn(new StreamReader(path + ".in"));
  62.             Console.SetOut(new StreamWriter(path + ".out"));
  63.         }
  64.         static void InitDebug(string path)
  65.         {
  66.             Console.SetIn(new StreamReader(path + ".in"));
  67.         }
  68.         #endregion
  69.  
  70.         static ulong Get(ulong days, ulong a, ulong k)
  71.         {
  72.             ulong dk = days / k;
  73.             ulong ans = (days - dk) * a;
  74.  
  75.             if (ans > inf) return inf;
  76.             else return ans;
  77.         }
  78.         static void Main()
  79.         {
  80.             InitIO(Name);
  81.             // InitDebug(Name);
  82.  
  83.             ulong[] args = (from arg in Console.ReadLine().Split(' ')
  84.                             select ulong.Parse(arg)).
  85.                             ToArray();
  86.  
  87.             ulong a = args[0];
  88.             ulong k = args[1];
  89.             ulong b = args[2];
  90.             ulong m = args[3];
  91.             ulong x = args[4];
  92.  
  93.             ulong ans = 0;
  94.             ulong min = 1;
  95.             ulong max = (inf / (a + b)) + (inf / (k + m)) + 1000;
  96.             max = Math.Min(inf, 2 * max);
  97.             while(min <= max)
  98.             {
  99.                 ulong c = (min + max) / 2;
  100.                  
  101.                 ulong v1 = Get(c, a, k);
  102.                 ulong v2 = Get(c, b, m);
  103.  
  104.                 ulong v = v1 + v2;
  105.                 if (v < x)
  106.                 {
  107.                     min = c + 1;
  108.                 }
  109.                 else
  110.                 {
  111.                     ans = c;
  112.                     max = c - 1;
  113.                 }
  114.             }
  115.  
  116.             Console.WriteLine(ans);
  117.             Console.Out.Flush();
  118.             Console.Out.Close();
  119.         }
  120.     }
  121. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement