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 题意:给你一个字符串,由‘.’和小写字母组成.把两个相邻的‘.’替换成一个‘.’,算一次变换.现在给你一些 ...
随机推荐
- Java SE 基础知识(二)
1. 类由两大部分构成:属性和方法.属性一般用名词来表示,方法一般用动词来表示. 2. 如果一个java源文件中定义了多个类,那么这些类中最多只能有一个类是public的,可以都不是public的. ...
- [转载]DropDownList三级菜单联动源码
using System; using System.Collections.Generic; using System.Linq; using System.Web; using System.We ...
- MySQL笔记(四)DDL与DML风格参考
便于 COPY ▲ 在所有操作之前: SET character_set_database=utf8; 确保 ↓ mysql> SHOW VARIABLES LIKE "%char%& ...
- jQuery API的特点
jQuery API 的特点 版权声明:未经博主授权,严禁转载分享 jQuery API 的三大特点 1. jQuery 对象是一个类数组对象,API自带遍历效果 - 对 jQuery 对象调用一次A ...
- ThinkPHP5跨控制器调用
1.在application\index\controller\文件夹里新建User.php <?php namespace app\index\controller; class User{ ...
- Node-webkit 安装使用npm安装模块方法
原文链接:http://jingyan.baidu.com/article/5225f26b5aaa20e6fa0908a6.html package.json可以放在软件根目录下,也可以放在项目目录 ...
- 基于qml创建最简单的图像处理程序(2)-使用c++&qml进行图像处理
<基于qml创建最简单的图像处理程序>系列课程及配套代码基于qml创建最简单的图像处理程序(1)-基于qml创建界面http://www.cnblogs.com/jsxyhelu/p/8 ...
- Android实践项目汇报(总结)
天气客户端开发报告 1 系统需求分析 1.1功能性需求分析 天气预报客户端,最基本就是为用户提供准确的天气预报信息.天气查询结果有两种:一种是当天天气信息,信息结果比较详细,除温度.天气状况外还 ...
- [算法整理]树上求LCA算法合集
1#树上倍增 以前写的博客:http://www.cnblogs.com/yyf0309/p/5972701.html 预处理时间复杂度O(nlog2n),查询O(log2n),也不算难写. 2#st ...
- 一个改写MBR的例子
前言 想要对MBR类的病毒进行一下研究与学习,在此期间,看了很多资料,其中帮助最大的就是金龟子学姐和willj学长发表的文章.一个从源码与实现角度来讲了一下,另外一个从反病毒角度来分析. 功能描述 ...