提交时间:2024-08-20 21:56:03

运行 ID: 173595

#include <iostream> #include <algorithm> using namespace std; struct Minister { int left; int right; }; bool compareMinisters(Minister a, Minister b) { return a.left * b.right < b.left * a.right; } int main() { int n; cin >> n; int kingLeft, kingRight; cin >> kingLeft >> kingRight; Minister ministers[n]; for (int i = 0; i < n; i++) { cin >> ministers[i].left >> ministers[i].right; } sort(ministers, ministers + n, compareMinisters); int maxReward = 0; int currentProduct = kingLeft; for (int i = 0; i < n; i++) { int reward = currentProduct / ministers[i].right; maxReward = max(maxReward, reward); currentProduct *= ministers[i].left; } cout << maxReward << endl; return 0; }