[codeforces1154F]Shovels Shop

time limit per test : 2 seconds
memory limit per test : 256 megabytes

here are n n n shovels in the nearby shop. The i i i-th shovel costs aibourles.
Misha has to buy exactly k k k shovels. Each shovel can be bought no more than once.
Misha can buy shovels by several purchases. During one purchase he can choose any subset of remaining (non-bought) shovels and buy this subset.
There are also m m m special offers in the shop. The j j j-th of them is given as a pair ( x j , y j ) (xj,yj) (xj,yj), and it means that if Misha buys exactly x j x_j xj shovels during one purchase then yj most cheapest of them are for free (i.e. he will not pay for y j y_j yj most cheapest shovels during the current purchase).
Misha can use any offer any (possibly, zero) number of times, but he cannot use more than one offer during one purchase (but he can buy shovels without using any offers).
Your task is to calculate the minimum cost of buying k k k shovels, if Misha buys them optimally.

Input

The first line of the input contains three integers n , m n,m n,m and k ( 1 ≤ n , m ≤ 2 ⋅ 1 0 5 , 1 ≤ k ≤ m i n ( n , 2000 ) ) k (1≤n,m≤2⋅10^5,1≤k≤min(n,2000)) k(1n,m2105,1kmin(n,2000)) — the number of shovels in the shop, the number of special offers and the number of shovels Misha has to buy, correspondingly.

The second line of the input contains n n n integers a 1 , a 2 , … , a n ( 1 ≤ a i ≤ 2 ⋅ 1 0 5 ) a_1,a_2,…,a_n (1≤a_i≤2⋅10^5) a1,a2,,an(1ai2105), where ai is the cost of the i i i-th shovel.

The next m lines contain special offers. The j j j-th of them is given as a pair of integers $(x_i,y_i) (1≤yi≤xi≤n) $and means that if Misha buys exactly x i x_i xi shovels during some purchase, then he can take y i y_i yi most cheapest of them for free.
Output

Print one integer — the minimum cost of buying k k k shovels if Misha buys them optimally.

Examples
Input

7 4 5
2 5 4 2 6 3 1
2 1
6 5
2 1
3 1

Output

7

Input

9 4 8
6 8 5 1 8 1 1 2 1
9 2
8 4
5 3
9 7

Output

17

Input

5 1 4
2 5 7 4 6
5 4

Output

17

Note

In the first example Misha can buy shovels on positions 1
and 4 (both with costs 2) during the first purchase and get one of them for free using the first or the third special offer. And then he can buy shovels on positions 3 and 6 (with costs 4 and 3) during the second purchase and get the second one for free using the first or the third special offer. Then he can buy the shovel on a position 7 with cost 1. So the total cost is 4+2+1=7.

In the second example Misha can buy shovels on positions 1
, 2, 3, 4 and 8 (costs are 6, 8, 5, 1 and 2) and get three cheapest (with costs 5, 1 and 2) for free. And then he can buy shovels on positions 6, 7 and 9 (all with costs 1) without using any special offers. So the total cost is 6+8+1+1+1=17.

In the third example Misha can buy four cheapest shovels without using any special offers and get the total cost 17.

题意:
给定n个铲子和他们的价格,你需要刚好买k个。你可以分开购买,对于每一个订单,有一些优惠,每个优惠表示为(x,y)如果这个订单的铲子数量为x,那么其中最便宜的y个可以免费。你不可以对一个订单使用多个优惠,但是你可以使用一种优惠多次在多个订单中。询问最少的花费。

题解:
先对铲子的价值排序(从小到大)
很显然我们只要买最小的k个就行了。
f[i]表示前i个铲子,被免费的铲子的价值总和是多少。
s[i]表示前i个铲子的价值之和。
p[i]表示买i个铲子,最多可以优惠的铲子的数量。
f [ i ] = m i n ( f [ i ] , f [ j ] + s [ j ] − s [ j + p [ i − j ] ] ) f[i]=min(f[i],f[j]+s[j]-s[j+p[i-j]]) f[i]=min(f[i],f[j]+s[j]s[j+p[ij]]) ( j &lt; i ) (j &lt; i) (j<i)
非常愚蠢地把序列dp写成背包写了2小时,果然还是自己太蠢。

#include<bits/stdc++.h>
#define LiangJiaJun main
#define ll long long
#define INF 199912270000LL
using namespace std;
int n,m,k;
ll a[200004],s[200004];
int p[200004];
ll f[200004];
int LiangJiaJun(){
	scanf("%d%d%d",&n,&m,&k);
	a[0]=0;
	for(int i=1;i<=n;i++)scanf("%lld",&a[i]);
	memset(p,0,sizeof(p));
	for(int i=1;i<=m;i++){
        int x,y;
        scanf("%d%d",&x,&y);
        p[x]=max(p[x],y);
	}
	sort(a+1,a+n+1);
	a[0]=0;
	for(int i=1;i<=n;i++)s[i]=s[i-1]+a[i];
	ll sum=s[k];
	memset(f,0,sizeof(f));
    for(int i=1;i<=k;i++){
        for(int j=0;j<i;j++){
            f[i]=max(f[i],f[j]+s[j+p[i-j]]-s[j]);
        }
    }
    printf("%lld\n",sum-f[k]);
	return 0;
}
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值