F. Shovels Shop
time limit per test

2 seconds

memory limit per test

256 megabytes

input

standard input

output

standard output

There are nn shovels in the nearby shop. The ii -th shovel costs aiai bourles.

Misha has to buy exactly kk 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 mm special offers in the shop. The jj -th of them is given as a pair (xj,yj)(xj,yj) , and it means that if Misha buys exactly xjxj shovels during one purchase then yjyj most cheapest of them are for free (i.e. he will not pay for yjyj 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 kk shovels, if Misha buys them optimally.

Input

The first line of the input contains three integers n,mn,m and kk (1≤n,m≤2⋅105,1≤k≤min(n,2000)1≤n,m≤2⋅105,1≤k≤min(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 nn integers a1,a2,…,ana1,a2,…,an (1≤ai≤2⋅1051≤ai≤2⋅105 ), where aiai is the cost of the ii -th shovel.

The next mm lines contain special offers. The jj -th of them is given as a pair of integers (xi,yi)(xi,yi) (1≤yi≤xi≤n1≤yi≤xi≤n ) and means that if Misha buys exactly xixi shovels during some purchase, then he can take yiyi most cheapest of them for free.

Output

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

Examples
Input

Copy
7 4 5
2 5 4 2 6 3 1
2 1
6 5
2 1
3 1
Output

Copy
7
Input

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

Copy
17
Input

Copy
5 1 4
2 5 7 4 6
5 4
Output

Copy
17
Note

In the first example Misha can buy shovels on positions 11 and 44 (both with costs 22 ) 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 33 and 66 (with costs 44 and 33 ) 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 77 with cost 11 . So the total cost is 4+2+1=74+2+1=7 .

In the second example Misha can buy shovels on positions 11 , 22 , 33 , 44 and 88 (costs are 66 , 88 , 55 , 11 and 22 ) and get three cheapest (with costs 55 , 11 and 22 ) for free. And then he can buy shovels on positions 66 , 77 and 99 (all with costs 11 ) without using any special offers. So the total cost is 6+8+1+1+1=176+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 1717 .

 #include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
const int maxn = *1e5+;
int a[maxn];
/*s表示前i件物品中的总花费,
g代表前i件物品中最多能免费的件数
dp代表前i件物品中最大能够节省的钱
*/
int s[maxn],g[maxn],dp[maxn]; int main(){
int n,m,k;
cin>>n>>m>>k;
for( int i=; i<=n; i++ ){
cin>>a[i];
}
sort(a+,a++n);
for( int i=; i<=n; i++ ){
s[i]=s[i-]+a[i];//前缀和
}
for( int i=; i<=m; i++ ){
int x,y;
cin>>x>>y;
g[x]=max(g[x],y);//最大减少数
}
for( int i=; i<=k; i++ ){
for( int j=; j<i; j++ ){
dp[i]=max(dp[i],dp[j]+s[j+g[i-j]]-s[j]);
}
}
cout<<s[k]-dp[k];
return ;
}

CF F. Shovels Shop(前缀和预处理+贪心+dp)的更多相关文章

  1. Codeforces Round #552 (Div. 3) F. Shovels Shop (前缀和预处理+贪心+dp)

    题目:http://codeforces.com/contest/1154/problem/F 题意:给你n个商品,然后还有m个特价活动,你买满x件就把你当前的x件中最便宜的y件价格免费,问你买k件花 ...

  2. cf F. Shovels Shop

    https://codeforces.com/contest/1154/problem/F 给定m个折扣 每个折扣的{x,y}的意思是每次购买如果买到确切的x只铲子就其中的最便宜的y只铲子免付: 先贪 ...

  3. F. Shovels Shop 背包DP

    题意: 商店里有n把铲子 每个铲子有其标价 一个人要买k吧 有m个优惠政策 每个优惠政策有两个元素x,y 表示   正好买x个铲子的时候  这x个铲子中最便宜的y个铲子免单 求用最少的前买到k个铲子 ...

  4. Codeforces Round #552 (Div. 3) F. Shovels Shop(dp)

    题目链接 大意:给你n个物品和m种优惠方式,让你买k种,问最少多少钱. 思路:考虑dpdpdp,dp[x]dp[x]dp[x]表示买xxx种物品的最少花费,然后遍历mmm种优惠方式就行转移就好了. # ...

  5. CF 628C --- Bear and String Distance --- 简单贪心

    CF 628C 题目大意:给定一个长度为n(n < 10^5)的只含小写字母的字符串,以及一个数d,定义字符的dis--dis(ch1, ch2)为两个字符之差, 两个串的dis为各个位置上字符 ...

  6. BZOJ-1587|前缀和 预处理 dp||叶子合并leaves

    叶子合并leaves Description 在一个美丽的秋天,丽丽每天都经过的花园小巷落满了树叶,她决定把树叶堆成K堆,小巷是笔直的 共有N片树叶(树叶排列也是笔直的),每片树叶都有一个重量值,并且 ...

  7. HDU 5550 - Game Rooms(DP + 前缀和预处理)

    链接: http://acm.hdu.edu.cn/showproblem.php?pid=5550 题意: 一个大楼有n(2≤n≤4000)层,每层可以建一个乒乓球房或者一个游泳房,且每种房间在大楼 ...

  8. LightOJ-1007-Mathematically Hard-欧拉函数打表+前缀和+预处理

    Mathematically some problems look hard. But with the help of the computer, some problems can be easi ...

  9. 【BZOJ-3174】拯救小矮人 贪心 + DP

    3174: [Tjoi2013]拯救小矮人 Time Limit: 1 Sec  Memory Limit: 128 MBSubmit: 686  Solved: 357[Submit][Status ...

随机推荐

  1. JAVA学习笔记(1)—— eclipse自动补全和主题及字体配置

    1.自动补全功能 (1)打开 Eclipse -> Window -> Perferences (2)选择Java -> Editor -> Content Assist -& ...

  2. redis集群伸缩【转】

    一:实验介绍 在不影响集群对外服务的情况下,可以为集群添加节点进行扩容,也可以下线部分节点进行缩容. 原理可以抽象为槽和对应数据在不同节点之间灵活移动. 如果希望加入一个节点来实现集群扩容时,需要通过 ...

  3. linux 安装虚拟机

    如果虚拟机创建不了就重启电脑 重启时 按下F2 出现后 第二个 往下 有个默认的 那个那个 打开虚拟机 选择第一个 然后是选择语言选择软件里面的 软件选择选择 基本网页服务器(右侧选择 python ...

  4. UMeditor控制多张图片上传顺序

    多张图片上传的顺序,受到用户使用习惯.插件上传和插件插入页面顺序的影响. 估计是考虑到上传性能,官方没有提供UMeditor控制展示顺序的配置.在上传过程中,用户点击拖动的第一张图片,将作为文件数组中 ...

  5. Unity 5.x动态加载光照信息(所有坑已踩)

    能搜到这的应该是被新的烘焙系统坑了少时间,4.x到5.x美术必须重新烘焙,关于美术的没什么说的,只有---重新烘焙! 新的烘焙系统,为了兼容5.x的多场景编辑功能,将烘焙信息从mesh全部挪到了一个中 ...

  6. Oracle数据库体系结构之进程结构(4)

    Oracle进程结构包括用户进程,服务进程,后台进程. 1. 用户进程 用户进程在数据库用户要求连接到Oracle服务器时开始启动. 用户进程是要求Oracle服务器交互的一种进程 它必须首先建立一个 ...

  7. 【Linux】在Win10上搭建WSL(适用于Linux的Windows子系统)

    1.打开WSL  ,控制面板 -- 程序 -- 程序和功能 -- 打开或关闭Windows功能 - 选中[适用于Linux的Windows子系统] 2.开启后重启电脑 3.在Win10自带的Micro ...

  8. CAShapLayer的使用1

    1.添加橙色圆环 - (CAShapeLayer *)shapeLayer { if (!_shapeLayer) { _shapeLayer = [CAShapeLayer layer]; CGRe ...

  9. DDD - 概述 - 聚合 (三)

    不要再看那些理论啦,说的云里雾里的,绕到你怀疑人生 一句话概括聚合创建:聚合的一致性决定了聚合边界的确定,决定了聚合对象的创建.所谓的一致性即事务的一致性,细化就是 立即性和原子性.

  10. tensorflow RNN循环神经网络 (分类例子)-【老鱼学tensorflow】

    之前我们学习过用CNN(卷积神经网络)来识别手写字,在CNN中是把图片看成了二维矩阵,然后在二维矩阵中堆叠高度值来进行识别. 而在RNN中增添了时间的维度,因为我们会发现有些图片或者语言或语音等会在时 ...