E. Change-free

Student Arseny likes to plan his life for n days ahead. He visits a canteen every day and he has already decided what he will order in each of the following n days. Prices in the canteen do not change and that means Arseny will spend ci rubles during the i-th day.

There are 1-ruble coins and 100-ruble notes in circulation. At this moment, Arseny has m coins and a sufficiently large amount of notes (you can assume that he has an infinite amount of them). Arseny loves modern technologies, so he uses his credit card everywhere except the canteen, but he has to pay in cash in the canteen because it does not accept cards.

Cashier always asks the student to pay change-free. However, it‘s not always possible, but Arseny tries to minimize the dissatisfaction of the cashier. Cashier‘s dissatisfaction for each of the days is determined by the total amount of notes and coins in the change. To be precise, if the cashier gives Arseny x notes and coins on the i-th day, his dissatisfaction for this day equals x·wi. Cashier always gives change using as little coins and notes as possible, he always has enough of them to be able to do this.

"Caution! Angry cashier"

Arseny wants to pay in such a way that the total dissatisfaction of the cashier for n days would be as small as possible. Help him to find out how he needs to pay in each of the n days!

Note that Arseny always has enough money to pay, because he has an infinite amount of notes. Arseny can use notes and coins he received in change during any of the following days.

Input

The first line contains two integers n and m (1?≤?n?≤?105, 0?≤?m?≤?109) — the amount of days Arseny planned his actions for and the amount of coins he currently has.

The second line contains a sequence of integers c1,?c2,?...,?cn (1?≤?ci?≤?105) — the amounts of money in rubles which Arseny is going to spend for each of the following days.

The third line contains a sequence of integers w1,?w2,?...,?wn (1?≤?wi?≤?105) — the cashier‘s dissatisfaction coefficients for each of the following days.

Output

In the first line print one integer — minimum possible total dissatisfaction of the cashier.

Then print n lines, the i-th of then should contain two numbers — the amount of notes and the amount of coins which Arseny should use to pay in the canteen on the i-th day.

Of course, the total amount of money Arseny gives to the casher in any of the days should be no less than the amount of money he has planned to spend. It also shouldn‘t exceed 106 rubles: Arseny never carries large sums of money with him.

If there are multiple answers, print any of them.

Examples

Input

5 42117 71 150 243 2001 1 1 1 1

Output

791 171 02 02 432 0

Input

3 0100 50 501 3 2

Output

1501 01 00 50

Input

5 42117 71 150 243 2005 4 3 2 1

Output

2301 171 01 503 02 0

发自内心的感觉要是我的水平是x,现在这个题的水平就是x+1,应该多做这样的题,我的水平才能变成x+1;

废话不多说,现在我们来讲一下这个问题:

假设我们现在的到x的最优解为sum,这个是最小的东西,然后我们添加一个thing,这个thing的带来的bad权值就是(100-a[i])*w[i];

要是现在我还有money我他妈的肯定要买的对吗? 那么现在我的value是不增加的,要是我没有钱没这个东西,假设我们前面的就是最优的解

那么我们怎么确保加不加这个东西啊,或者说加了这个东西要去掉或者增加前面的那些东西,这是我们要解决的两个问题,

问题1: 我们加不加这个东西,要是前面的最小bad权值<当前的bad权值我们一定要加上这个东西的,要是不加的话结果肯定不是最优的,那么我们现在   要做的就是决定去掉哪个东西,我们去掉的肯定是最小的bad权值对应的编号,这是很显然的,但是我们现在又要思考去掉了这个东西,我们剩下的钱还能不能买前面的其他的东西了,答案是肯定不能买的,这个地方逻辑水平还是很高的,

假设当前的thing需要的coin为x,前面的最小的bad去掉后,我们现在有的coin=100+原来的coin1;

coin1<x 要是等于的话就能买了。 买了x后我们还有100+coin1-x; 这个东西肯定是小于100的那么说之前不能买的东西贡献的值为y

就相当于100-它需要的coin  ,  y+coin2<x  现在我们有100+coin2+y-x;我们要是能买前面的东西的话,我们最少的钱要是100-y

100+coin2+y-x<100-y

时间: 2024-07-29 21:00:01

E. Change-free的相关文章

centos yum安装ftp 及解决vsftp错误500 OOPS: cannot change directory:/home/**

centos yum安装ftp 及解决vsftp错误500 OOPS: cannot changedirectory:/home/**   1.查看服务器有没有安装ftp包 rpm -qa |grep vsftp 2.yum  安装 yum -y install vsftpd 3.启动vsftp的服务 service vsftpd start 4.关闭防火墙 service iptables stop 5.测试匿名访问 修改配置文件 vsftpd.conf [[email protected]

How to change SMTP Banner, HELO,EHLO Greetings for Zimbra

1- Take Zimbra backup or VM snapshot before doing any changes 2- Enter the following command to change SMTP Banner: # su - zimbra $ zmlocalconfig -e postfix_smtpd_banner="yourmailserver.yourdomain.com" 3- Then if you want to change HELO/EHLO nam

【oracle】oracledba4 when you need to change storage options

In which scenarios would you rebuild an index? (Choose all that a pply.) A. when you need to disable the index usage B. when you need to change storage options C. when you need to enable index monitoring D. when you need to move the index to another 

zoj 2156 - Charlie&#39;s Change

题目:钱数拼凑,面值为1,5,10,25,求组成n面值的最大钱币数. 分析:dp,01背包.需要进行二进制拆分,否则TLE,利用数组记录每种硬币的个数,方便更新. 写了一个 多重背包的 O(NV)反而没有拆分快.囧,最后利用了状态压缩优化 90ms: 把 1 cents 的最后处理,其他都除以5,状态就少了5倍了. 说明:貌似我的比大黄的快.(2011-09-26 12:49). #include <stdio.h> #include <stdlib.h> #include <

eclipse中,项目有红叉之-Cannot change version of project facet Dynamic Web Module to 3.1

1.打开Problems查看错误原因Window->Show View->Other->General->Problems 2.查看问题 3.发现是Cannot change version of project facet Dynamic Web Module to 3.1 4.根据2里截图的Resource,得到是哪个项目,项目右击->Properties->Project Faces->Dynamic Web Module,更据相应Dynamic Web M

Linux指令类型(一)change指令

一.change指令 chattr chgrp chmod chown chfn chsh chroot 二.ch指令详细介绍 (1)chattr 全名:change attribute 作用:chattr命令用于改变文件属性 语法:chattr [-RV][-v<版本编号>][+/-/=<属性>][文件或目录...] 参数: -R 递归处理,将指定目录下的所有文件及子目录一并处理. -v<版本编号> 设置文件或目录版本. -V 显示指令执行过程. +<属性>

多个jdk 变更 引起 tomcat插件 启动不了 The JRE could not be found.Edit the server and change the JRE location.

The JRE could not be found.Edit the server and change the JRE location. 在Windows->Preferences->Server->Runtime Environments 选择Tomcat->Edit,在jre中选择相应的jdk版本,完事.

[转]解决Cannot change version of project facet Dynamic web module to 2.5

我们用Eclipse创建Maven结构的web项目的时候选择了Artifact Id为maven-artchetype-webapp,由于这个catalog比较老,用的servlet还是2.3的,而一般现在至少都是2.5,在Project Facets里面修改Dynamic web module为2.5的时候就会出现Cannot change version of project facet Dynamic web module to 2.5,如图: 其实在右边可以看到改到2.5需要的条件以及有

CentOS -bash: warning: setlocale: LC_MESSAGES: cannot change locale (en_US.UTF-8)

centos5.x 登陆显示: -bash: warning: setlocale: LC_CTYPE: cannot change locale (en_US.UTF-8): No such file or directory-bash: warning: setlocale: LC_COLLATE: cannot change locale (en_US.UTF-8): No such file or directory-bash: warning: setlocale: LC_MESSAG

[Ramda] Change Object Properties with Ramda Lenses

In this lesson we'll learn the basics of using lenses in Ramda and see how they enable you to focus changes on specific properties of an object while keeping your data immutable. what 'R.lens' do is able to get or set prop value but keep the object i