CodeForces - 1154F

There are n shovels in the nearby shop. The i-th shovel costs ai

bourles.

Misha has to buy exactly 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

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

shovels, if Misha buys them optimally.

Input

The first line of the input contains three integers n,m

and k (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 n

integers a1,a2,…,an (1≤ai≤2⋅105), where ai is the cost of the i

-th shovel.

The next m

lines contain special offers. The j-th of them is given as a pair of integers (xi,yi) (1≤yi≤xi≤n) and means that if Misha buys exactly xi shovels during some purchase, then he can take yi

most cheapest of them for free.

Output

Print one integer — the minimum cost of buying 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张票,m种优惠(买x张票,免最便宜的y张票),买k张票

解法:排序,对前k张票dp。

#include <bits/stdc++.h>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <algorithm>
#include <iostream>
#include <cstdio>
#include <string>
#include <stdio.h>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <string.h>
#include <vector>
#define ME(x , y) memset(x , y , sizeof(x))
#define SF(n) scanf("%d" , &n)
#define rep(i , n) for(int i = 0 ; i < n ; i ++)
#define INF 0x3f3f3f3f
#define mod 1000000007
#define PI acos(-1)
using namespace std;
typedef long long ll ;
const int N = 1e7 + ;
int a[] , sum[];
int x[] , y[];
int dp[]; int main()
{
int n , m , k;
scanf("%d%d%d" , &n , &m , &k);
for(int i = ; i <= n ; i++)
{
scanf("%d" , &a[i]);
}
for(int i = ; i <= m ; i++)
{
scanf("%d%d" , &x[i] , &y[i]);
}
sort(a+ , a+n+);
for(int i = ; i <= n ; i++)
{
sum[i] = sum[i-]+a[i];
}
for(int i = ; i <= k ; i++)
{
dp[i] = sum[i];
for(int j = ; j <= m ; j++)
{
if(i >= x[j])
{
dp[i] = min(dp[i] , dp[i-x[j]]+sum[i]-sum[i-x[j]+y[j]]);//如果要用该张优惠卷
//那就从原来票数量中减去x【j】张,加上新的没有免费的票价(减去了免费的票价)。
}
}
}
cout << dp[k] << endl ; return ;
}

dp(买票优惠)的更多相关文章

  1. JDOJ 1928: 排队买票

    JDOJ 1928: 排队买票 JDOJ传送门 Description 一场演唱会即将举行.现有n个歌迷排队买票,一个人买一张,而售票处规定,一个人每次最多只能买两张票.假设第i位歌迷买一张票需要时间 ...

  2. FZU 2029 买票问题 树状数组+STL

    题目链接:买票问题 思路:优先队列维护忍耐度最低的人在队首,leave操作ok. vis数组记录从1到n的编号的人们是不是在队列中,top维护队首的人的编号.pop操作搞定. 然后,check操作就是 ...

  3. java多线程编程(3)买票

    1,买票非同步版本 http://www.cnblogs.com/anbylau2130/archive/2013/04/17/3025347.html很详细 public class 多线程2 { ...

  4. 你好,C++(37)上车的人请买票!6.3.3 用虚函数实现多态

    6.3.3  用虚函数实现多态 在理解了面向对象的继承机制之后,我们知道了在大多数情况下派生类是基类的“一种”,就像“学生”是“人”类中的一种一样.既然“学生”是“人”的一种,那么在使用“人”这个概念 ...

  5. Java 数量为5的线程池同时运行5个窗口买票,每隔一秒钟卖一张票

    /** * 1.创建线程数量为5的线程池 * 2.同时运行5个买票窗口 * 3.总票数为100,每隔一秒钟卖一张票 * @author Administrator * */ public class ...

  6. 杭电1133 排队买票 catalan

    Buy the Ticket Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)To ...

  7. poj 2828 Buy Tickets 【买票插队找位置 输出最后的位置序列+线段树】

    题目地址:http://poj.org/problem?id=2828 Sample Input 4 0 77 1 51 1 33 2 69 4 0 20523 1 19243 1 3890 0 31 ...

  8. java 多线程之synchronized wait/notify解决买票问题

    一.Java线程具有五中基本状态 新建状态(New):当线程对象对创建后,即进入了新建状态,如:Thread t = new MyThread(); 就绪状态(Runnable):当调用线程对象的st ...

  9. python8.4景区买票

    from threading import Threadimport threadinglock=threading.Lock()num=100#定义买票方法def sale(name): lock. ...

随机推荐

  1. 给Java新手的一些建议----Java知识点归纳(J2EE and Web 部分)

    J2EE(Java2 Enterprise Edition) 刚出现时一般会用于开发企业内部的应用系统,特别是web应用,所以渐渐,有些人就会把J2EE和web模式画上了等号.但是其实 J2EE 里面 ...

  2. Python---进阶---函数式编程---按照权重排序

    一. 权重是100 价格占的权重是40%,销量占的权重是17%,评级站的权重是13%,评论占的权重是30% ---------------------------------------------- ...

  3. mongdb 数据库

    安装mongdb 下载地址 https://www.runoob.com/mongodb/mongodb-window-install.html 检查 mongdb 是否安装成功which mongd ...

  4. FileUtils (从磁盘下载,从网络下载)

    public class FileUtils { /** * realPath 磁盘路径 D://project/download/ * urlPath 后半部分路径 具体根据业务需求,例如:WEB- ...

  5. 【转载】MIMO技术杂谈(一):鱼与熊掌能否兼得?--浅谈分集与复用的权衡

    原文链接(向作者致敬):http://www.txrjy.com/thread-667901-1-1.html   无线通信世界在过去的几十年中的发展简直是爆发式的,MIMO(多发多收)技术的出现更是 ...

  6. PHP高手干货分享:不能不看的50个细节!【PHP培训教程】

    兄弟连分享PHP高手干货:不能不看的50个细节 1.用单引号代替双引号来包含字符串,这样做会更快一些.因为PHP会在双引号包围的字符串中搜寻变量,单引号则不会,注意:只有echo能这么做,它是一种可以 ...

  7. HDU 6205 card card card ( 思维 )

    题意 : 给定两个序列 a 和 b ,保证 a 数列的和 == b数列的和,从头到尾考虑 (a[i] - b[i]) 的前缀和,直到前缀和为负数则无法进行下去,所得的便是a[1~i]的和,现在有一个操 ...

  8. 【bzoj1588】[HNOI2002]营业额统计

    题目描述: 营业额统计 Tiger最近被公司升任为营业部经理,他上任后接受公司交给的第一项任务便是统计并分析公司成立以来的营业情况. Tiger拿出了公司的账本,账本上记录了公司成立以来每天的营业额. ...

  9. Qt Creator 启动失败 可能的解决办法

    用了一段时间Qt Creator莫名的打开失败   重装一遍,仍然不行: 网上搜到解决办法:删除 ~\AppData\Roaming\QtProject文件夹. linux下:~是/home/Your ...

  10. js中switch语句不执行

    参考http://www.jb51.net/article/54393.htm switch语句与if语句的关系最为密切,也是其它编程语言中普遍使用的一种流程控制语句,但switch的匹配是全等模式, ...