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.IO;
- using System.Text;
- using System.Threading.Tasks;
- namespace region
- {
- class Program
- {
- const ulong inf = 1000000000000000000;
- const string Name = "forest";
- #region Read
- static string[] Split(string s)
- {
- return s.Split(" ".ToCharArray(), StringSplitOptions.RemoveEmptyEntries);
- }
- static int ReadInt()
- {
- return int.Parse(Console.ReadLine());
- }
- static long ReadLong()
- {
- return long.Parse(Console.ReadLine());
- }
- static double ReadDouble()
- {
- return double.Parse(Console.ReadLine());
- }
- static int[] ReadArrayL()
- {
- int l = ReadInt();
- return ReadArray(Split(Console.ReadLine()), l);
- }
- static int[] ReadArray()
- {
- return ReadArray(Split(Console.ReadLine()));
- }
- static int[] ReadArray(int count)
- {
- return ReadArray(Split(Console.ReadLine()), count);
- }
- static int[] ReadArray(string[] args)
- {
- return ReadArray(args, args.Length);
- }
- static int[] ReadArray(string[] args, int count)
- {
- int[] res = new int[count];
- for (int i = 0; i < count; i++)
- {
- res[i] = int.Parse(args[i]);
- }
- return res;
- }
- #endregion
- #region Init
- static void InitIO(string path)
- {
- Console.SetIn(new StreamReader(path + ".in"));
- Console.SetOut(new StreamWriter(path + ".out"));
- }
- static void InitDebug(string path)
- {
- Console.SetIn(new StreamReader(path + ".in"));
- }
- #endregion
- static ulong Get(ulong days, ulong a, ulong k)
- {
- ulong dk = days / k;
- ulong ans = (days - dk) * a;
- if (ans > inf) return inf;
- else return ans;
- }
- static void Main()
- {
- InitIO(Name);
- // InitDebug(Name);
- ulong[] args = (from arg in Console.ReadLine().Split(' ')
- select ulong.Parse(arg)).
- ToArray();
- ulong a = args[0];
- ulong k = args[1];
- ulong b = args[2];
- ulong m = args[3];
- ulong x = args[4];
- ulong ans = 0;
- ulong min = 1;
- ulong max = (inf / (a + b)) + (inf / (k + m)) + 1000;
- max = Math.Min(inf, 2 * max);
- while(min <= max)
- {
- ulong c = (min + max) / 2;
- ulong v1 = Get(c, a, k);
- ulong v2 = Get(c, b, m);
- ulong v = v1 + v2;
- if (v < x)
- {
- min = c + 1;
- }
- else
- {
- ans = c;
- max = c - 1;
- }
- }
- Console.WriteLine(ans);
- Console.Out.Flush();
- Console.Out.Close();
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement