题解:P10862 [HBCPC2024] Spicy or Grilled?

· · 题解

题意

一共有 n 个人,有 x 人个需要买品种二,品种一需要 a 元,品种二需要 b 元,一共需要多少元。

思路

根据题意可得,买品种一的人有 n - x 个人,那么需要的钱数总和为 (n - x) \times a + x \times b。

注意 T 组数据!

代码

#include <bits/stdc++.h>
using namespace std;
int t;
signed main(){
    ios_base::sync_with_stdio(false);
    cin.tie(0), cout.tie(0);
    cin >> t;
    while(t--){
        int n, x, a, b;
        cin >> n >> x >> a >> b;
        cout << (n - x) * a + x * b << "\n";
    }
    return 0;
}