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 题意:给你一个字符串,由‘.’和小写字母组成.把两个相邻的‘.’替换成一个‘.’,算一次变换.现在给你一些 ...
随机推荐
- 数据仓库原理<3>:数据仓库与ODS
1. 引言 本篇主要讲述操作数据存储(ODS)系统产生的背景.定义.特点,以及它与数据仓库的区别. 在前两篇,笔者介绍了什么是数据仓库?为什么需要数据仓库?数据仓库系统的体系结构是什么?因此可能在读者 ...
- python之路----TCP与UDP
TCP import socket #tcp协议 sk = socket.socket() # 买手机 创建一个socket对象 sk.bind(('127.0.0.1',8080)) # 给serv ...
- bzoj1698 / P1606 [USACO07FEB]白银莲花池Lilypad Pond
P1606 [USACO07FEB]白银莲花池Lilypad Pond 转化为最短路求解 放置莲花的方法如果直接算会有重复情况. 于是我们可以先预处理和已有莲花之间直接互相可达的点,将它们连边(对,忽 ...
- java反射field和method的顺序问题
最近在有思考到序列化性能优化的问题,关于java反射field和method的顺序问题,这里有详细的讨论http://stackoverflow.com/questions/5001172/java- ...
- 20145333茹翔 Exp8 Web基础
20145333茹翔 Exp8 Web基础 实验问题回答 (1)什么是表单 表单是一个包含表单元素的区域,表单元素是允许用户在表单中(比如:文本域.下拉列表.单选框.复选框等等)输入信息的元素,表单在 ...
- 在awk中通过system调用sql语句来说明引号的使用
一个实际应用例子: 在awk中,通过system调用连接数据库并作select操作,select语句中where条件来自于一个文件(file)的第一个域($1). $ cat file ... ... ...
- 全球变暖|2018年蓝桥杯B组题解析第九题-fishers
标题:全球变暖 你有一张某海域NxN像素的照片,"."表示海洋."#"表示陆地,如下所示: ....... .##.... .##.... ....##. .. ...
- git 指定要提交的ssh key
问题描述 ssh具有-i选项,用于告知在验证时使用哪个私钥文件: -i identity_file Selects a file from which the identity (private ke ...
- 'curl' is not recognized as an internal or external command
使用everything搜索本地的curl.exe发现如下 官网查看最新版本https://curl.haxx.se/windows/ 2019-03-06 最新版本7.64.0 curl-7.64. ...
- 用 C# 计算 与 java 一致的unix时间戳 (长时间整形 如:1476956079961)
背景: 调用java提供接口,需要长时间整形作为验证. 预备知识: 1. java 的 System.currentTimeMillis() 计算的长整型,是从1970年1月1日开始,截止当前的毫秒数 ...