C - Bolero

Time Limit:1000MS     Memory Limit:65536KB     64bit IO Format:%I64d & %I64u

Description

Winter in Yekaterinburg is the longest time of the year. And everyone spends long winter evenings in his own way. Denis is a big fan of classical music, at least twice a week he attends concerts at the Philharmonic.
This year, Denis wants to buy tickets for the whole season at once and even already has chosen a list of concerts, which he wants to attend. Now, he thinks, how to buy tickets. There is an opportunity in the Philharmonic to choose any k or more concerts and to buy a single subscription for all of them. The cost of this subscription will be equal to the total cost of all concerts in it but with a discount ppercent. There are many types of such subscriptions, with different k and p. In addition, for some concerts Denis, as a student, has a discount. This discount is valid only if he buys the ticket separately, outside the subscription.
Denis, like any other poor student, wants to attend all the concerts, spending as little money as possible. However, he knows that there are always more people wanting to attend a concert than the number of seats in the Philharmonic hall. So he will not buy more than one ticket for one concert (separately or in a subscription), even if it allows him to save money.

Input

The first line contains integers n and m that are the number of concerts Denis wants to attend, and a number of different subscription types at the Philharmonic (2 ≤ n ≤ 10 5; 1 ≤ m ≤ 10 5). The i-th of the following n lines contains integers si and di that are the price of a ticket and the discount for students in percent at the i-th concert (100 ≤ si ≤ 50 000; 0 ≤ di ≤ 100). The  j-th of the following m lines contains integers kj and pj that are the minimum number of concerts that can be combined in the subscription of the j-th type, and a discount for it in percent (2 ≤ kj ≤ n; 1 ≤ pj ≤ 100).

Output

Output the minimum amount of money Denis has to spend to attend all the concerts. The answer should be given with an absolute or relative error not exceeding 10 −6.

Sample Input

input output
6 2
500 0
700 0
300 0
400 0
500 50
800 0
5 10
6 15
2680.00

Notes

In the example, Denis needs to buy a subscription of the first type (with 10% discount) for all concerts, except the fifth one, and to buy a ticket for the fifth concert with a student discount of 50%.
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <vector>
#include <queue>
#include <cstring>
#include <string>
#include <algorithm>
using namespace std;
typedef long long ll; #define MM(a,b) memset(a,b,sizeof(a));
#define inf 0x7f7f7f7f
#define FOR(i,n) for(int i=1;i<=n;i++)
#define CT continue;
#define PF printf
#define SC scanf
const int maxn=100000+10; struct node{
ll val;int id;
bool operator<(const node &a) const{
return this->val>a.val;
}
};
vector<int> G[105];
priority_queue<node> q;
int num[105],g[105];
int main()
{
int n,m;
while(~SC("%d%d",&n,&m)){
ll ori=0,ans=0;
for(int i=0;i<=100;i++) G[i].clear();
FOR(i,n) {
int cost,p;
SC("%d%d",&cost,&p);
ori+=cost*(100-p);
G[p].push_back(cost);
}
for(int i=0;i<=100;i++) sort(G[i].begin(),G[i].end());
MM(num,inf);
FOR(i,m){
int peo,dis;
SC("%d%d",&peo,&dis);
num[dis]=min(num[dis],peo);
}
// PF("111111\n");
ans=ori;
FOR(k,100){
if(num[k]>n) CT;
MM(g,0);
// PF("2222222\n");
ll tmp=ori,cnt=0;
for(int i=0;i<=k;i++)
for(int j=0;j<G[i].size();j++){
tmp+=G[i][j]*(i-k);cnt++;
}
// PF("3333333\n");
while(q.size()) q.pop();
for(int i=k+1;i<=100;i++) {
if(G[i].size()) q.push((node){G[i][0]*(i-k),i});
g[i]=1;
}
// PF("444444\n");
while(cnt<num[k]){
node u=q.top();q.pop();
tmp+=u.val;
cnt++;
if(g[u.id]<G[u.id].size()){
int r=g[u.id];
q.push((node){G[u.id][r]*(u.id-k),u.id});
g[u.id]++;
}
}
ans=min(ans,tmp);
}
PF("%.2f\n",(double)ans/100.00);
}
return 0;
}

  错点:如果直接枚举优惠券的优惠值大小k(0-100),然后,计算出每种票在此优惠券下的可优惠

价格,再sort排下序是100*1e5*log1e5是会超时的,所以需要优化一下,考虑买单个票的时候,打的折

<=k的必须要算(可优惠),对于>k的,对每种k,每次都只能选其中的一种(贪心),所以,可用优先队列将复杂度降到1e5log100,

注意==k的也必须要贪啊,,因为要让大与k的数量尽可能小

最新文章

  1. python学习-day14-前端之html、css
  2. java.lang.NoClassDefFoundError: com/sun/mail/util/LineInputStreamsJavamail问题
  3. 20145317彭垚《Java程序设计》实验二
  4. bzoj 3218 a + b Problem(最小割+主席树)
  5. Instructions Set JAVA_HOME System-Wide
  6. phonegap退出android程序
  7. XSS【跨站脚本攻击】
  8. maven指定部署的服务器类型
  9. “百度杯”CTF比赛 九月场_Code(PhpStorm)
  10. Python之路【第一篇】:Python简介和入门
  11. 记事本:一些js案例以及DOM和BOM
  12. 集合之LinkedList(含JDK1.8源码分析)
  13. 【APP测试(Android)】--升级更新
  14. 枚举类型enum详解——C语言
  15. Spring 消息
  16. Redis(一)入门
  17. js使用正则替换掉所有的“”
  18. VS2015常用快捷键
  19. easyUI实现(alert)提示框自动关闭的实例代码
  20. JAVA对象的深度克隆

热门文章

  1. vbs 简单文件操作
  2. c# 多线程使用队列顺序写日志的类 (需要再优化)
  3. 【科创人&#183;独家】连续创业者高春辉的这六年:高强度投入打造全球领先的IP数据库
  4. JQuery 判断复选框是否选中
  5. SmartBinding与kbmMW#3
  6. C++二叉树前中后序遍历(递归&amp;非递归)统一代码格式
  7. 合并K个sorted list
  8. Codeforces 1082 毛毛虫图构造&amp;最大权闭合子图
  9. 纯c中声明变量
  10. notepad++ 二进制插件