题目链接

大意:Arseny有m个1元硬币, 无限多100元钞票, 他要按顺序买n个东西,

第i天如果找零x个硬币, 他的不满值会加 w[i]*x, 求最少不满值.

若找零, 则硬币增加 100-ci%100, ans增加(100-ci%100)*wi

不找零, 则硬币增加 -ci%100, ans不变

贪心尽量不找零, 如果需要找零, 可以发现更改任意一个均会增加100个硬币

所以直接选一个对ans贡献最少的改为找零即可

需要特判100的倍数, 一定不能找零

#include <iostream>
#include <queue>
#include <cstdio>
#define REP(i,a,n) for(int i=a;i<=n;++i)
#define x first
#define y second
using namespace std;
typedef long long ll;
typedef pair<int,int> pii; const int N = 4e5+, INF = 0x3f3f3f3f;
int n, m;
int c[N], w[N];
int vis[N]; int main() {
cin>>n>>m;
REP(i,,n) cin>>c[i];
REP(i,,n) cin>>w[i];
priority_queue<pii,vector<pii>,greater<pii> > q;
ll ans = ;
REP(i,,n) if (c[i]%) {
q.push(pii((-c[i]%)*w[i],i));
if (m<c[i]%) {
vis[q.top().y] = ;
m += ;
ans += q.top().x;
q.pop();
}
m-=c[i]%;
}
cout<<ans<<endl;
REP(i,,n) {
if (vis[i]) cout<<c[i]/+<<' '<<<<'\n';
else cout<<c[i]/<<' '<<c[i]%<<'\n';
}
}

Change-free CodeForces - 767E (贪心)的更多相关文章

  1. CodeForces - 893D 贪心

    http://codeforces.com/problemset/problem/893/D 题意 Recenlty Luba有一张信用卡可用,一开始金额为0,每天早上可以去充任意数量的钱.到了晚上, ...

  2. Codeforces Round #427 (Div. 2) Problem B The number on the board (Codeforces 835B) - 贪心

    Some natural number was written on the board. Its sum of digits was not less than k. But you were di ...

  3. Codeforces Round #424 (Div. 2, rated, based on VK Cup Finals) Problem D (Codeforces 831D) - 贪心 - 二分答案 - 动态规划

    There are n people and k keys on a straight line. Every person wants to get to the office which is l ...

  4. Codeforces Round #423 (Div. 2, rated, based on VK Cup Finals) Problem D (Codeforces 828D) - 贪心

    Arkady needs your help again! This time he decided to build his own high-speed Internet exchange poi ...

  5. Codeforces 767E Change-free

    题目链接:http://codeforces.com/contest/767/problem/E 居然是一个瞎几把贪心(E比B水系列) 考虑要每一次操作至少要用${\left \lfloor \fra ...

  6. CodeForces - 93B(贪心+vector<pair<int,double> >+double 的精度操作

    题目链接:http://codeforces.com/problemset/problem/93/B B. End of Exams time limit per test 1 second memo ...

  7. 【codeforces 767E】Change-free

    [题目链接]:http://codeforces.com/problemset/problem/767/E [题意] 你有m个1元硬币和无限张100元纸币; 你在第i天,需要花费ci元; 同时在第i天 ...

  8. C - Ordering Pizza CodeForces - 867C 贪心 经典

    C - Ordering Pizza CodeForces - 867C C - Ordering Pizza 这个是最难的,一个贪心,很经典,但是我不会,早训结束看了题解才知道怎么贪心的. 这个是先 ...

  9. Codeforces 570C 贪心

    题目:http://codeforces.com/contest/570/problem/C 题意:给你一个字符串,由‘.’和小写字母组成.把两个相邻的‘.’替换成一个‘.’,算一次变换.现在给你一些 ...

随机推荐

  1. python 用正则表达式把”0102030405”分成5组('0', '1'), ('0', '2'), ('0', '3'), ('0', '4'), ('0', '5')

    把”0102030405”分成5组('0', '1'), ('0', '2'), ('0', '3'), ('0', '4'), ('0', '5') re.findall(r"(\d)(\ ...

  2. js 技巧(智能社教程温故)

    1.js 中  NaN === NaN  值为false; 2.parseInt("abc") === NaN;(不是数字) 3.tab 纯js 实现.可以给当前循环的元素添加.i ...

  3. pm2 观察报错时 pm2 start app.js --watch

    pm2 start app.js --watch[PM2][ERROR] Script already launched, add -f option to force re-execution

  4. B轮公司技术问题列表

    B轮公司技术问题列表 1.异构系统的接口对接我们有自己的一套统一接口,但是需要与其它公司的接口做对接,但是各个公司的接口各不相同,有什么好的方式能够方便与各公司的接口做对接的同时我们这边也能尽量少或者 ...

  5. ajax return true/false无效原因

    错误示例:function checkCP(customerId,productId){ $.ajax({ url:"/cp/checkCP", type:"post&q ...

  6. P3456 [POI2007]GRZ-Ridges and Valleys(bfs)

    P3456 [POI2007]GRZ-Ridges and Valleys 八个方向都跑一遍bfs,顺便判断一下是山峰还是山谷,或者是山坡(俩都不是) (实在不知道要说啥了qwq) #include& ...

  7. STM32.SPI(25Q16)

    1.首先认识下W25Q16DVSIG, SOP8 SPI FLASH 16MBIT  2MB(4096个字节) (里面可以放字库,图片,也可以程序掉电不丢失数据放里面) 例程讲解: ① 1.用到SPI ...

  8. Codeforces Round#413 Problem A - C

    Problem#A Carrot Cakes vjudge链接[here] (偷个懒,cf链接就不给了) 题目大意是说,烤面包,给出一段时间内可以考的面包数,建第二个炉子的时间,需要达到的面包数,问建 ...

  9. DTMF在VOIP中的解决方案

    双音多频DTMF(Dual Tone Multi-Frequency)信令,因其提供更高的拨号速率,迅速取代了传统转盘式电话机使用的拨号脉冲信令.DTMF也应用在交互式控制中,诸如语言菜单.语言邮件. ...

  10. linux 之awk命令详解

    awk是一种程序语言,对文档资料的处理具有很强的功能.awk名称是由它三个最初设计者的姓氏的第一个字母而命名的: Alfred V. Aho.Peter J. We i n b e rg e r.Br ...