【codeforces 767E】Change-free
【题目链接】: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的更多相关文章
- 【codeforces 415D】Mashmokh and ACM(普通dp)
[codeforces 415D]Mashmokh and ACM 题意:美丽数列定义:对于数列中的每一个i都满足:arr[i+1]%arr[i]==0 输入n,k(1<=n,k<=200 ...
- 【codeforces 779E】Bitwise Formula
[题目链接]:http://codeforces.com/contest/779/problem/E [题意] 给你n个长度为m的二进制数 (有一些是通过位运算操作两个数的形式给出); 然后有一个未知 ...
- 【codeforces 785E】Anton and Permutation
[题目链接]:http://codeforces.com/problemset/problem/785/E [题意] 给你一个初始序列1..n顺序 然后每次让你交换任意两个位置上面的数字; 让你实时输 ...
- 【codeforces 798C】Mike and gcd problem
[题目链接]:http://codeforces.com/contest/798/problem/C [题意] 给你n个数字; 要求你进行若干次操作; 每次操作对第i和第i+1个位置的数字进行; 将 ...
- 【52.49%】【codeforces 556A】Case of the Zeros and Ones
time limit per test1 second memory limit per test256 megabytes inputstandard input outputstandard ou ...
- 【27.91%】【codeforces 734E】Anton and Tree
time limit per test3 seconds memory limit per test256 megabytes inputstandard input outputstandard o ...
- 【33.10%】【codeforces 604C】Alternative Thinking
time limit per test2 seconds memory limit per test256 megabytes inputstandard input outputstandard o ...
- 【40.17%】【codeforces 569B】Inventory
time limit per test1 second memory limit per test256 megabytes inputstandard input outputstandard ou ...
- 【codeforces 757C】Felicity is Coming!
time limit per test2 seconds memory limit per test256 megabytes inputstandard input outputstandard o ...
随机推荐
- NYIST 1083 美丽的校园
美丽的校园时间限制:1000 ms | 内存限制:65535 KB难度:3 描述 美丽的校园需要大家维护,作为南工学子,当然有责任! 在计科系门前有n棵树,按一行排列在计科系楼前面,它们在一条直线上, ...
- VirtualBox安装kali linux过程及安装后无法全屏问题解决方法(2)
? 1 安装说完了,现在来看看怎么全屏吧,虚拟机无法全屏跟咸鱼有什么区别... 首先打开vbox,选择设备(Device)选项里面最下面安装增强工具那个选项(insert guest additi ...
- byte类型取值范围以及溢出具体解释
例1: public class test { public static void main(String[] args) { byte a = 127 ; a = (byte)(a+3) ; Sy ...
- DesignPattern_Java:Factory Method Pattern
工厂方法模式 Factory Method :(虚拟构造函数模式 Virtual Constructor,多态性工厂模式 Ploymorphic Facoty) Define an interface ...
- redis 五大数据类型的常用指令
STRING 192.168.1.66:6379> get k1 "v1" 192.168.1.66:6379> append k1 12345 (integer) 7 ...
- 【转】用CocoaPods做iOS程序的依赖管理 -- 不错
原文网址:http://blog.devtang.com/2014/05/25/use-cocoapod-to-manage-ios-lib-dependency/ 文档更新说明 2012-12-02 ...
- 院校-德国:亚琛工业大学(RWTH)
ylbtech-院校-德国:亚琛工业大学(RWTH) 1.返回顶部 1. 亚琛工业大学(RWTH)成立于1870年,是德国著名理工类大学之一,也是世界顶尖理工类大学之一 ,长久以来被誉为“欧洲的麻省理 ...
- kafka windows安装 命令行下使用测试
1.zookeeper安装: (https://zookeeper.apache.org/releases.html) ①进入zookeeper的相关设置所在的文件目录,例如本文的:D:\bigd ...
- ROS-多机通信
前言:一定要在同一路由的局域网下进行,就是两台电脑的ip要像这样:192.168.191.4和192.168.191.8,只有最后一位不同,这样就能ping通了,否则ping不同. 一.查看ip和主机 ...
- Android Fragment RecycleListView
1.新建SuperActivity package com.example.ting.criminalintentpractise; import android.os.Bundle;import a ...