1 solutions
-
0
Guest MOD
-
0
首先读取商品数量 和优惠券数量 。 接着读取 件商品的价格,累加得到商品的原始总价 。 然后遍历 张优惠券,对于每张优惠券,判断商品原始总价是否大于等于优惠券的满减条件 ,如果满足,就将优惠金额 累加到 中。 最后用商品原始总价 减去总优惠金额 ,得到小 A 最少需要支付的金额
#include <iostream> #include <vector> using namespace std; int main() { int n, m; cin >> n >> m; vector<int> prices(n); for (int i = 0; i < n; i++) cin >> prices[i]; int totalPrice = 0; for (int price : prices) totalPrice += price; vector<pair<int, int>> coupons(m); for (int i = 0; i < m; i++) cin >> coupons[i].first >> coupons[i].second; int totalDiscount = 0; for (auto coupon : coupons) { if (totalPrice >= coupon.first) totalDiscount += coupon.second; } int result = totalPrice - totalDiscount; if (result < 0) result = 0; cout << result << endl; return 0; }
- 1
Information
- ID
- 1509
- Time
- 1000ms
- Memory
- 256MiB
- Difficulty
- 7
- Tags
- (None)
- # Submissions
- 167
- Accepted
- 33
- Uploaded By