Change-free CodeForces - 767E (贪心)
大意: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 (贪心)的更多相关文章
- CodeForces - 893D 贪心
http://codeforces.com/problemset/problem/893/D 题意 Recenlty Luba有一张信用卡可用,一开始金额为0,每天早上可以去充任意数量的钱.到了晚上, ...
- 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 ...
- 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 ...
- 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 ...
- Codeforces 767E Change-free
题目链接:http://codeforces.com/contest/767/problem/E 居然是一个瞎几把贪心(E比B水系列) 考虑要每一次操作至少要用${\left \lfloor \fra ...
- 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 ...
- 【codeforces 767E】Change-free
[题目链接]:http://codeforces.com/problemset/problem/767/E [题意] 你有m个1元硬币和无限张100元纸币; 你在第i天,需要花费ci元; 同时在第i天 ...
- C - Ordering Pizza CodeForces - 867C 贪心 经典
C - Ordering Pizza CodeForces - 867C C - Ordering Pizza 这个是最难的,一个贪心,很经典,但是我不会,早训结束看了题解才知道怎么贪心的. 这个是先 ...
- Codeforces 570C 贪心
题目:http://codeforces.com/contest/570/problem/C 题意:给你一个字符串,由‘.’和小写字母组成.把两个相邻的‘.’替换成一个‘.’,算一次变换.现在给你一些 ...
随机推荐
- linux常用命令:用SecureCRT来上传和下载文件
用SSH管理linux服务器时经常需要远程与本地之间交互文件.而直接用SecureCRT自带的上传下载功能无疑是最方便的,SecureCRT下的文件传输协议有ASCII.Xmodem.Zmodem. ...
- emoj表情过滤
用法: isEmojiCharacter(input_value) // 提交时候校验.true:emoj表情 undefined:无 if(isEmojiCharacter(val) ...
- java接口对接——调用别人接口推送数据
实际开发中经常会遇到要和其他平台或系统对接的情况,实际操作就是互相调用别人的接口获取或者推送数据, 当我们调用别人接口推送数据时,需要对方给一个接口地址以及接口的规范文档,规范中要包括接口的明确入参及 ...
- TED #09# You don't have to be an expert to solve big problems
Tapiwa Chiwewe: You don't have to be an expert to solve big problems Collection noticed a haze hangi ...
- SNMP学习笔记之Python的netsnmp和pysnmp的性能对比
0x00 概览 用python获取snmp信息有多个现成的库可以使用,其中比较常用的是netsnmp和pysnmp两个库.网上有较多的关于两个库的例子. 本文重点在于如何并发的获取snmp的数据,即同 ...
- 深入JAVA注解之属性注解
项目目录结构 实体类: package org.guangsoft.annotation.entity; import java.lang.annotation.ElementType; import ...
- 06: linux下python开发环境梳理
1.1 修改~/.bashrc文件 改编终端颜色 alias rm='rm -i' alias cp='cp -i' alias mv='mv -i' # User specific aliases ...
- C_Learning(2)
/指针 /指针变量指向一个变量的地址 /给指针变量赋的值只能是地址 /指针变量的赋值 /{ int a; int *p; p=&a; } or { int a; int *p=&a; ...
- 实现windows命令提示符的tab补全
1:使用win+r打开 运行 控制台 2:输入 regedit 打开注册表 3:进入 HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Command Processor\C ...
- 20145327 《网络对抗》MSF基础应用
20145327 <网络对抗>MSF基础应用 主动攻击ms08_067 两台虚拟机,其中一台为kali,一台为windows xp sp3(英文版) kali ip地址:192.168.4 ...