CF261A Maxim and Discounts -- 贪心

Description

在商场中,有m种的折扣,当你买的东西到qi个的时候,可以使用该种类型的折扣,对要买的东西进行免费,东西可以免费最至多2个
免费的条件是,你所选择进行免费的东西,不能超过已经在购物车的中最便宜的商品
问买所有的物品,使用这些打折规则,使得付的钱最少。

Solution

读题可发现:

  • 每种优惠类型可以使用无数次 => 明示贪心(每次都用要求最少的那种)
  • 所选择进行免费的东西,不能超过已经在购物车的中最便宜的商品狡猾 精明的商人)=> 所以最好就是从大到小依次买,能优惠时直接跳两个
    (我不知道怎么脑子抽风了,想到从大到小的顺序以后还在顺序做…浪费了半个多小时)

代码如下:

#include <algorithm>
#include <iostream>
#include <cstring>
#include <cstdio>
#include <vector>
#include <cmath>
#include <queue>
#include <map>
#include <set>
#define il inline
#define re register
using namespace std;
typedef long long ll;
const int maxn = 1e5 + 10;
int n, q;
int discount[maxn], a[maxn];
ll ans = 0;
il bool cmp(int x, int y) {
	return x > y;
}
int main() {
	scanf("%d", &q);
	for(re int i = 1; i <= q; ++i) 
		scanf("%d", &discount[i]);
	sort(discount+1, discount+q+1);
	scanf("%d", &n);
	for(re int i = 1; i <= n; ++i)
		scanf("%d", &a[i]);
	sort(a+1, a+n+1, cmp);
	int cnt = 0, tmp = discount[1];
	for(re int i = 1; i <= n; ++i) {
		if(cnt == tmp) {
			cnt = 0;
			i += 2;
		}
		cnt++;
		ans += a[i];
	}
	printf("%lld\n", ans);
	return 0;
}



评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值