Artifact Content
Not logged in

Artifact 076d8405b22e14c4810c953f1f4d29dfd08608e0


#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 StrongEconomy { public:

	long long earn(long long n, long long k, long long price, long long target) 
	{
		if( target/n < k )
			return 1;

		LL best = target;
		for(LL money=0, round=0; round+1<best;)
		{
			// ここから何もしなかった場合のラウンド数
			best = min(best, round + roundsNeededToEarn(target-money, n*k));

			// (n,k) を増やせる様になるまで待つ
			if( money < price )
			{
				LL rp = roundsNeededToEarn(price-money, n*k);
				round += rp;
				money += n*k*rp;
			}

			// (n,k) を増やしてみる
			//   - もう増やさない方がいい可能性は「何もしなかった場合」で考慮済み
			//   - 今増やさず後で増やす方がいい、ということはあり得ない
			(n<k ? n : k)++;
			money -= price;
		}
		return best;
	}

	LL roundsNeededToEarn(LL t, LL v)
	{
		return (t-1)/v + 1;
	}
};

// 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> ostream& operator<<(ostream& os, const vector<T>& v)
 { os << "{ ";
   for(typename vector<T>::const_iterator it=v.begin(); it!=v.end(); ++it)
   os << '\"' << *it << '\"' << (it+1==v.end() ? "" : ", "); os << " }"; return os; }
void verify_case(const long long& Expected, const long long& Received) {
 bool ok = (Expected == Received);
 if(ok) cerr << "PASSED" << timer() << endl;  else { cerr << "FAILED" << timer() << endl;
 cerr << "\to: \"" << Expected << '\"' << endl << "\tx: \"" << Received << '\"' << endl; } }
#define CASE(N) {cerr << "Test Case #" << N << "..." << flush; start_time=clock();
#define END	 verify_case(_, StrongEconomy().earn(n, k, price, target));}
int main(){

CASE(0)
	long long n = 2LL; 
	long long k = 1LL; 
	long long price = 2LL; 
	long long target = 10LL; 
	long long _ = 4LL; 
END
CASE(1)
	long long n = 2LL; 
	long long k = 1LL; 
	long long price = 2LL; 
	long long target = 9LL; 
	long long _ = 3LL; 
END
CASE(2)
	long long n = 1LL; 
	long long k = 1LL; 
	long long price = 500000LL; 
	long long target = 1000002LL; 
	long long _ = 1000001LL; 
END
CASE(3)
	long long n = 5LL; 
	long long k = 4LL; 
	long long price = 15LL; 
	long long target = 100LL; 
	long long _ = 5LL; 
END
CASE(4)
	long long n = 1000000000000LL; 
	long long k = 1000000000000LL; 
	long long price = 1000000000000LL; 
	long long target = 1000000000000LL; 
	long long _ = 1LL; 
END
CASE(5)
	long long n = 1LL; 
	long long k = 1LL; 
	long long price = 1000000000000LL; 
	long long target = 1000000000000LL; 
	long long _ = 1000000000000LL; 
END
CASE(6)
	long long n = 1LL; 
	long long k = 1LL; 
	long long price = 1LL; 
	long long target = 1000000000000LL; 
	long long _ = 8LL; 
END

}
// END CUT HERE