Created
February 9, 2023 07:18
-
-
Save PreciousNyasulu/6e13ebd4fdaad290c1a7af22f04764b2 to your computer and use it in GitHub Desktop.
Problem #2
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
class Program | |
{ | |
static int MaxPumpPower(int[] fields, int[] waterTowers) | |
{ | |
Array.Sort(fields); | |
Array.Sort(waterTowers); | |
int i = 0, j = 0, maxDistance = 0; | |
while (i < fields.Length && j < waterTowers.Length) | |
{ | |
if (fields[i] <= waterTowers[j]) | |
{ | |
maxDistance = Math.Max(maxDistance, waterTowers[j] - fields[i]); | |
i++; | |
} | |
else | |
{ | |
j++; | |
} | |
} | |
return maxDistance; | |
} | |
static void Main(string[] args) | |
{ | |
int[] fields = { 1, 5}; | |
int[] waterTowers = {10 }; | |
Console.WriteLine(MaxPumpPower(fields, waterTowers)); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment