All pastes #1648880 Raw Edit

Candles Optimization

public cpp v1 · immutable
#1648880 ·published 2009-10-30 05:22 UTC
rendered paste body
#include <iostream>#include <algorithm>#include <functional>#include <vector>int main(int argc, char *argv[]){	int n;	std::cout<<"Enter the number of candles."<<std::endl;	std::cin>>n;	std::vector<int> c;	std::cout<<"Enter the lengths of the candles."<<std::endl;	int temp;	while(n--){		std::cin>>temp;		c.push_back(temp);	}	int no_of_days=0;	while(!c.empty()){		if(c.size()>no_of_days){			no_of_days++;			std::sort(c.begin(), c.end(), std::greater<int>());			std::transform(c.begin(), c.begin()+no_of_days, c.begin(), 				std::bind2nd(std::minus<int>(), 1) );			c.erase(std::remove(c.begin(), c.end(), 0), c.end());		}else{			break;		}	}	std::cout<<"No. of days the event can go on = "<<no_of_days<<std::endl;}/*Sample Run :rahul@kodersbox:~/Desktop$ ./candlesEnter the number of candles.6Enter the lengths of the candles.2 4 5 3 5 1No. of days the event can go on = 5*/