From d5eda379913acc2b643b2186f67b8c06ba68d315 Mon Sep 17 00:00:00 2001 From: ritvik-garg <70766301+ritvik-garg@users.noreply.github.com> Date: Mon, 12 Oct 2020 20:06:25 +0530 Subject: [PATCH] Create GREEDY_FOREST.cpp --- Algorithms/Greedy/GREEDY_FOREST.cpp | 44 +++++++++++++++++++++++++++++ 1 file changed, 44 insertions(+) create mode 100644 Algorithms/Greedy/GREEDY_FOREST.cpp diff --git a/Algorithms/Greedy/GREEDY_FOREST.cpp b/Algorithms/Greedy/GREEDY_FOREST.cpp new file mode 100644 index 00000000..e12db32e --- /dev/null +++ b/Algorithms/Greedy/GREEDY_FOREST.cpp @@ -0,0 +1,44 @@ +/* +Problem : GREEDY FOREST +Link : https://www.hackerrank.com/challenges/greedy-florist/problem +*/ + +// SOLUTION : +#include +#include + +using namespace std; +int main(){ + + int n,k,i,j; + cin>>n>>k; + int y,arr[n],x=1; + long sum=0; + for(i=0;i>arr[i]; + sort(arr,arr+n,greater()); + + if(n%k==0) + y=n/k; + else + y=(n/k)+1; + i=0; + while(y>0) + { + for(j=0;j