【题目链接】:http://codeforces.com/problemset/problem/767/E

【题意】



你有m个1元硬币和无限张100元纸币;

你在第i天,需要花费ci元;

同时在第i天,收银员有一个不高兴程度wi;

然后如果它要找零x张纸币y枚硬币的话,它的不高兴值会为wi*(x+y)

找的零钱会回到你的口袋里;

问你n天的,总的最小不高兴值;

【题解】



整百的部分,直接用纸币填就好了;

则直接对ci%100考虑;

即要直接用硬币填满ci%100,或者是先给一张100,然后让他找你钱;

如果m>=ci;

则直接用硬币填它,这样不会有不满意;

m-=ci;

然后记录如果给一张纸币的话,会增加多少不满意度;

放入优先队列中;

如果m< ci;

则考虑修改之前的贪心;

如果优先队列的第一个元素比w[i]*(100-a[i])小;

则把之前的那一个修改成用一张纸币填;

然后那时因为已经减去ci了,所以修改的话,硬币数直接加上100;

而这100可以保证够把当前的ci用硬币填

则,用硬币填就是了;

如果不满足优先队列的第一个元素比w[i]*(100-a[i])小;

则这个用一张纸币填;



【Number Of WA】



0



【完整代码】

#include <bits/stdc++.h>
using namespace std;
#define lson l,m,rt<<1
#define rson m+1,r,rt<<1|1
#define LL long long
#define rep1(i,a,b) for (int i = a;i <= b;i++)
#define rep2(i,a,b) for (int i = a;i >= b;i--)
#define mp make_pair
#define pb push_back
#define fi first
#define se second
#define ms(x,y) memset(x,y,sizeof x)
#define Open() freopen("F:\\rush.txt","r",stdin)
#define Close() ios::sync_with_stdio(0),cin.tie(0) typedef pair<int,int> pii;
typedef pair<LL,LL> pll; const int dx[9] = {0,1,-1,0,0,-1,-1,1,1};
const int dy[9] = {0,0,0,-1,1,-1,1,-1,1};
const double pi = acos(-1.0);
const int N = 1e5+100; struct abc
{
LL val,id;
friend bool operator < (abc a,abc b)
{
if (a.val!=b.val)
return a.val>b.val;
else
return a.id<b.id;
}
}; LL n,m;
LL ans1[N],ans2[N],a[N],w[N];
priority_queue<abc> xiao; int main()
{
//Open();
Close();//scanf,puts,printf not use
//init??????
cin >> n >> m;
rep1(i,1,n)
{
cin >> a[i];
ans1[i]=a[i]/100;
a[i]%=100;
}
rep1(i,1,n)
cin >> w[i];
LL ans = 0;
rep1(i,1,n)
if (a[i])
{
if (m>=a[i])
{
m-=a[i];
xiao.push(abc{w[i]*(100-a[i]),i});
continue;
}
//m<a[i] if (xiao.empty())
{
m+=100-a[i];
ans+=w[i]*(100-a[i]);
ans2[i] = 1;
continue;
} if (xiao.top().val<w[i]*(100-a[i]))
{
ans2[xiao.top().id] = 1;
ans+=xiao.top().val;
xiao.pop();
m+=100;
m-=a[i];
xiao.push(abc{w[i]*(100-a[i]),i});
}
else
{
m+=100-a[i];
ans+=w[i]*(100-a[i]);
ans2[i] = 1;
}
}
cout << ans << endl;
rep1(i,1,n)
if (ans2[i])
cout << ans1[i]+1 <<' '<<0<<endl;
else
cout << ans1[i] <<' '<<a[i]<<endl;
return 0;
}

【codeforces 767E】Change-free的更多相关文章

  1. 【codeforces 415D】Mashmokh and ACM(普通dp)

    [codeforces 415D]Mashmokh and ACM 题意:美丽数列定义:对于数列中的每一个i都满足:arr[i+1]%arr[i]==0 输入n,k(1<=n,k<=200 ...

  2. 【codeforces 779E】Bitwise Formula

    [题目链接]:http://codeforces.com/contest/779/problem/E [题意] 给你n个长度为m的二进制数 (有一些是通过位运算操作两个数的形式给出); 然后有一个未知 ...

  3. 【codeforces 785E】Anton and Permutation

    [题目链接]:http://codeforces.com/problemset/problem/785/E [题意] 给你一个初始序列1..n顺序 然后每次让你交换任意两个位置上面的数字; 让你实时输 ...

  4. 【codeforces 798C】Mike and gcd problem

    [题目链接]:http://codeforces.com/contest/798/problem/C [题意] 给你n个数字; 要求你进行若干次操作; 每次操作对第i和第i+1个位置的数字进行; 将 ...

  5. 【52.49%】【codeforces 556A】Case of the Zeros and Ones

    time limit per test1 second memory limit per test256 megabytes inputstandard input outputstandard ou ...

  6. 【27.91%】【codeforces 734E】Anton and Tree

    time limit per test3 seconds memory limit per test256 megabytes inputstandard input outputstandard o ...

  7. 【33.10%】【codeforces 604C】Alternative Thinking

    time limit per test2 seconds memory limit per test256 megabytes inputstandard input outputstandard o ...

  8. 【40.17%】【codeforces 569B】Inventory

    time limit per test1 second memory limit per test256 megabytes inputstandard input outputstandard ou ...

  9. 【codeforces 757C】Felicity is Coming!

    time limit per test2 seconds memory limit per test256 megabytes inputstandard input outputstandard o ...

随机推荐

  1. 关于ajax异步请求不到数据的问题 302跨域请求

    项目大致问题是这样的 在线咨询模块的数据是通过ajax异步加载来请求到数据,然后动态解析并且显示 前台页面的请求代码 后台action: 另外就是这个项目还有一个登陆权限的认证,如果不登录后台或者登录 ...

  2. RobotFrameWork+APPIUM实现对安卓APK的自动化测试----第四篇【AppiumLibrary实用函数介绍】

    http://blog.csdn.net/deadgrape/article/details/50585677 通过前几篇的讲述,我相信大家已经对RF+Appium的框架已经有所了解了. 接下来我告诉 ...

  3. Java Pattern Matcher 正则表达式需要转义的字符

    见:http://blog.csdn.net/bbirdsky/article/details/45368709 /** * 转义正则特殊字符 ($()*+.[]?\^{},|) * * @param ...

  4. iOS推送 (百度推送)

    近期在使用推送,所以与大家分享一下我所遇到的问题,与解决这个问题的方法.! 1.首先生成CertificateSigningRequest文件. 点击钥匙串訪问-->从证书颁发机构请求证书--& ...

  5. JAVA项目中公布WebService服务——简单实例

    1.在Java项目中公布一个WebService服务: 怎样公布? --JDK1.6中JAX-WS规范定义了怎样公布一个WebService服务. (1)用jdk1.6.0_21以后的版本号公布. ( ...

  6. oracle存储过程的使用

    一. 使用for循环游标:遍历全部职位为经理的雇员 1. 定义游标(游标就是一个小集合) 2. 定义游标变量 3. 使用for循环游标 declare -- 定义游标c_job cursor c_jo ...

  7. js 预加载图片image()函数

    创建一个Image对象:var a=new Image();    定义Image对象的src: a.src=”xxx.gif”;    这样做就相当于给浏览器缓存了一张图片. 图像对象: 建立图像对 ...

  8. Extjs Grid 各种Demo

    grid的一个渲染效果 Ext.define('cfWeb.view.accountSetting.OrgManageView',{ alias : 'widget.orgManageView', e ...

  9. POJ 2771 最大独立集 匈牙利算法

    (为什么最大独立集的背景都是严打搞对象的( _ _)ノ|壁) 思路:匈牙利算法 没什么可说的-- // by SiriusRen #include <cstdio> #include &l ...

  10. 算法入门经典第七章 例题7-2-1 生成1-n的排列

    输入正数n,按字典序从小到大的顺序输出n个数的所有排列.两个序列的字典序大小关系等价于从头开始第一个不相同位置处的大小关系. 递归的边界应该很好理解吧,当集合s[]中没有一个元素的时候,按照上面的伪码 ...