Skip to content

Instantly share code, notes, and snippets.

@divyang4481
Created May 17, 2020 07:20
Show Gist options
  • Select an option

  • Save divyang4481/c8eb886c8fe403d0b1d5c0ad752b42d9 to your computer and use it in GitHub Desktop.

Select an option

Save divyang4481/c8eb886c8fe403d0b1d5c0ad752b42d9 to your computer and use it in GitHub Desktop.
The Powerpuff Girls
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
class CandidateCode {
static void Main(String[] args) {
//Write code here
var ingredientCount = long.Parse(System.Console.ReadLine());
var ingredientFormula =System.Console.ReadLine().Split(new char[]{' '},StringSplitOptions.RemoveEmptyEntries);
var ingredientStock = System.Console.ReadLine().Split(new char[]{' '},StringSplitOptions.RemoveEmptyEntries);
var result =CaculateMaxPowerpuffGirls(ingredientCount,
Array.ConvertAll(ingredientFormula, f => int.Parse(f.Trim())),
Array.ConvertAll(ingredientStock, s => int.Parse(s.Trim())));
System.Console.WriteLine(result);
}
static int CaculateMaxPowerpuffGirls(long ingredientCount, int[] ingredientFormula, int[] ingredientStock )
{
var count =0;
var hasEnoughIngredeint=true;
while(hasEnoughIngredeint)
{
for(int i=0 ; i<ingredientCount ;i++ )
{
if(ingredientStock[i]>=ingredientFormula[i])
{
ingredientStock[i] -=ingredientFormula[i];
}
else
{
hasEnoughIngredeint=false;
break;
}
}
if(hasEnoughIngredeint)
{
count++;
}
else
{
break;
}
}
return count;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment