File size: 727 Bytes
ff444f7 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 |
#include <algorithm>
#include <iostream>
using namespace std;
using int64 = long long;
int64 solve() {
int64 A, B, C;
cin >> A >> B >> C;
// Watch out for this nasty bug: 2*x/y != 2*(x/y).
// Remember to floor before multiplying!
// Option 1: Buy only singles.
int64 ans = C / A;
// Option 2: Buy only doubles.
ans = max(ans, 2*(C / B) - 1);
// Option 3: 1 single + maximum doubles.
if (C > A) {
ans = max(ans, 1 + 2*((C - A)/B));
}
// Option 4: 2 singles + maximum doubles.
if (C > 2*A) {
ans = max(ans, 2 + 2*((C - 2*A)/B));
}
return ans;
}
int main() {
int T;
cin >> T;
for (int t = 1; t <= T; t++) {
cout << "Case #" << t << ": " << solve() << endl;
}
return 0;
}
|