Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- class Program
- {
- static void Main()
- {
- int pipesN = int.Parse(Console.ReadLine());
- int friendsM = int.Parse(Console.ReadLine());
- int[] pipesArr = new int[pipesN];
- //int sum = 0;
- for (int i = 0; i < pipesN; i++)
- {
- pipesArr[i] = int.Parse(Console.ReadLine());
- //sum = sum + pipesArr[i];
- }
- int biggestNumber = int.MaxValue/2;
- int lowestNumber = 1;
- while (true)
- {
- int mid = (lowestNumber + biggestNumber) / 2;
- int currentSections = 0;
- int currentSectionsCompare = 0;
- for (int j = 0; j < pipesArr.Length; j++)
- {
- int helpTempNumber = pipesArr[j] / mid;
- int helpTempNumberComp = pipesArr[j] / (mid + 1);
- currentSections = currentSections + helpTempNumber;
- currentSectionsCompare = currentSectionsCompare + helpTempNumberComp;
- }
- if (currentSections == friendsM && currentSectionsCompare < friendsM)
- {
- Console.WriteLine(mid);
- Environment.Exit(0);
- }
- else if (currentSections >= friendsM)
- {
- lowestNumber = mid;
- }
- else //if (currentSections < friendsM)
- {
- biggestNumber = mid;
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement