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.Text;
- namespace _3.Tubes
- {
- class Tubes
- {
- static void Main(string[] args)
- {
- int n = int.Parse(Console.ReadLine());
- int m = int.Parse(Console.ReadLine());
- int[] tubes = new int[n];
- for (int i = 0; i < n; i++)
- {
- tubes[i] = int.Parse(Console.ReadLine());
- }
- bool haveSolution = false;
- int solutionLength = -1;
- int cutDownBorder = 0;
- int cutUpBorder = tubes.Max();
- int cutLength = cutUpBorder + cutDownBorder / 2;
- while (cutUpBorder - cutDownBorder > 1)
- {
- haveSolution = false;
- int tubeItems = 0;
- for (int j = 0; j < n; j++)
- {
- tubeItems += tubes[j] / cutLength;
- if (tubeItems >= m)
- {
- solutionLength = cutLength;
- haveSolution = true;
- break;
- }
- }
- if (haveSolution)
- {
- cutDownBorder = cutLength;
- }
- else
- {
- cutUpBorder = cutLength;
- }
- cutLength = (cutUpBorder + cutDownBorder) / 2;
- }
- Console.WriteLine(solutionLength);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement