PKU 2683 Ohgas' Fortune

  • やるだけ
int main() {
	int m;
	cin >> m;

	REP(caseIndex, m) {
		int money, year, n;
		cin >> money >> year >> n;
		int bestAnswer = 0;
		REP(typeIndex, n) {
			int type, cost;
			double ratio;
			cin >> type >> ratio >> cost;

			if (type) {
				// 複利
				int m = money;
				REP(y, year) {
					m = m + (int)(m * ratio) - cost;
				}
				bestAnswer = max(bestAnswer, m);

			} else {
				int m = money;
				int sum = 0;
				REP(y, year) {
					sum += (int)(m * ratio);
					m -= cost;
				}
				m += sum;
				bestAnswer = max(bestAnswer, m);
			}
		}

		cout << bestAnswer << endl;
	}
}