Artifact Content
Not logged in

Artifact b050d3607f1a5bd805eb9a9ef3b5156a9a933d50


#include <iostream>
#include <sstream>
#include <iomanip>
#include <vector>
#include <string>
#include <map>
#include <set>
#include <algorithm>
#include <numeric>
#include <iterator>
#include <functional>
#include <complex>
#include <queue>
#include <stack>
#include <cmath>
#include <cassert>
#include <cstring>
using namespace std;
typedef long long LL;
typedef complex<double> CMP;

class Shopping {
public:
	int minNumber(int X, vector <int> values) 
	{
		sort( values.begin(), values.end() );

		int next=1, cnt=0;
		while( next <= X )
		{
			// maximum <= next;
			vector<int>::iterator it = upper_bound(values.begin(), values.end(), next);
			if( it == values.begin() )
				return -1;
			next += *(it-1);
			++cnt;
		}
		return cnt;
	}
};

// BEGIN CUT HERE
#include <ctime>
double start_time;string timer() { ostringstream os; os << " (" << int((clock()-start_time)/CLOCKS_PER_SEC*1000) << " msec)"; return os.str(); }

template <typename T> string print_array(const vector<T> &V) { ostringstream os; os << "{ "; for (typename vector<T>::const_iterator iter = V.begin(); iter != V.end(); ++iter) os << '\"' << *iter << "\","; os << " }"; return os.str(); }
int verify_case(const int &Expected, const int &Received) { if (Expected == Received) cerr << "PASSED" << timer() << endl; else { cerr << "FAILED" << timer() << endl; cerr << "\tExpected: \"" << Expected << '\"' << endl; cerr << "\tReceived: \"" << Received << '\"' << endl; } return 0;}

template<int N> struct Case_ { Case_(){start_time=clock();} };
char Test_(...);
int Test_(Case_<0>) {
	int X = 20; 
	int values_[] = {1, 2, 5, 10};
	  vector <int> values(values_, values_+sizeof(values_)/sizeof(*values_)); 
	int RetVal = 5; 
	return verify_case(RetVal, Shopping().minNumber(X, values)); }
int Test_(Case_<1>) {
	int X = 7; 
	int values_[] = {2, 4, 1, 7};
	  vector <int> values(values_, values_+sizeof(values_)/sizeof(*values_)); 
	int RetVal = 3; 
	return verify_case(RetVal, Shopping().minNumber(X, values)); }
int Test_(Case_<2>) {
	int X = 20; 
	int values_[] = {2,4,6,8};
	  vector <int> values(values_, values_+sizeof(values_)/sizeof(*values_)); 
	int RetVal = -1; 
	return verify_case(RetVal, Shopping().minNumber(X, values)); }
int Test_(Case_<3>) {
	int X = 600; 
	int values_[] = {1,2,3,10,11,30};
	  vector <int> values(values_, values_+sizeof(values_)/sizeof(*values_)); 
	int RetVal = 25; 
	return verify_case(RetVal, Shopping().minNumber(X, values)); }

template<int N> void Run_() { cerr << "Test Case #" << N << "..." << flush; Test_(Case_<N>()); Run_<sizeof(Test_(Case_<N+1>()))==1 ? -1 : N+1>(); }
template<>      void Run_<-1>() {}
int main() { Run_<0>(); }
// END CUT HERE