题解 P13554 【MX-X15-T1】奶龙龙
非常简单的一个分类讨论题目。
思路
有两种情况:
- 当购买
a 奶龙未触发促销价时,即a<y 时。此时最优情况可能是恰好购买a 个;也有可能是购买y 个,可以有优惠,所以答案是x \times a 与y \times z 的最小值。 - 当购买
a 奶龙已经触发促销价时,由于题目保证z \leq x ,所以答案就是a \times z ;
由于数据很小,故可以 short 水过。
代码
#include<bits/stdc++.h>
using namespace std;
short x,y,z,a;
int main(){
ios::sync_with_stdio(false);
cin.tie(0);
cin>>x>>y>>z>>a;
if(a<y)
cout<<min(x*a,y*z);
else
cout<<a*z;
return 0;
}