#include <cstdio> #include <iostream> #include <algorithm> #include <queue> #include <cmath> #include <cstring> #include <stack> #include <set> #include <map> #include <vector> using namespace std; #define INF 0x4fffffff #define LL long long #define MAX(a,b) ((a)>(b))?(a):(b) #define MIN(a,b) ((a)<(b))?(a):(b) int main(){ int t; cin >> t; while(t--){ int n,m,p,q; scanf("%d%d%d%d",&n,&m,&p,&q); int ans = 0; if(q < m*p){ ans = (n/m)*q; n = n % m; } if(n < m){ if(n * p < q){ ans += n * p; } else{ ans += q; } } else{ ans = p * n; } printf("%d\n",ans); } return 0; }
版权声明:本文为博主原创文章,未经博主允许不得转载。
时间: 2024-10-10 13:31:42