Advertisement
stanevplamen

02.09.05.03.Tubes

Jul 12th, 2013
82
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.44 KB | None | 0 0
  1. using System;
  2.  
  3. class Program
  4. {
  5.     static void Main()
  6.     {
  7.         int pipesN = int.Parse(Console.ReadLine());
  8.         int friendsM = int.Parse(Console.ReadLine());
  9.         int[] pipesArr = new int[pipesN];
  10.  
  11.         //int sum = 0;
  12.         for (int i = 0; i < pipesN; i++)
  13.         {
  14.             pipesArr[i] = int.Parse(Console.ReadLine());
  15.             //sum = sum + pipesArr[i];
  16.         }
  17.  
  18.         int biggestNumber = int.MaxValue/2;
  19.         int lowestNumber = 1;
  20.  
  21.         while (true)
  22.         {
  23.             int mid = (lowestNumber + biggestNumber) / 2;
  24.             int currentSections = 0;
  25.             int currentSectionsCompare = 0;
  26.             for (int j = 0; j < pipesArr.Length; j++)
  27.             {
  28.                 int helpTempNumber = pipesArr[j] / mid;
  29.                 int helpTempNumberComp = pipesArr[j] / (mid + 1);
  30.                 currentSections = currentSections + helpTempNumber;
  31.                 currentSectionsCompare = currentSectionsCompare + helpTempNumberComp;
  32.             }
  33.             if (currentSections == friendsM && currentSectionsCompare < friendsM)
  34.             {
  35.                 Console.WriteLine(mid);
  36.                 Environment.Exit(0);
  37.             }
  38.             else if (currentSections >= friendsM)
  39.             {
  40.                 lowestNumber = mid;
  41.             }
  42.             else //if (currentSections < friendsM)
  43.             {
  44.                 biggestNumber = mid;
  45.             }
  46.         }
  47.     }  
  48. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement