直接贪心,如果生产采矿的玩意能在剩余时间里挖到更多的矿,就生产它,先判断,再累加
// Problem#: 1620
// Submission#: 3250111
// The source code is licensed under Creative Commons Attribution-NonCommercial-ShareAlike 3.0 Unported License
// URI: http://creativecommons.org/licenses/by-nc-sa/3.0/
// All Copyright reserved by Informatic Lab of Sun Yat-sen University
#include<iostream>
using namespace std;
int main() {
int test;
cin >> test;
while (test--) {
int N, M, C, P, S;
cin >> N >> M >> C >> P >> S;
while (S) {
if (S * C > P) {
N = N + M / P;
M = M % P;
}
M += N * C;
S--;
}
cout << M << endl;
}
}