CF767E.Change-free

提高+/省选-

通过率:0%

时间限制:1.00s

内存限制:256MB

AC君温馨提醒

该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。

题目描述

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 c__i 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·w__i. 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.

学生阿尔谢尼喜欢提前规划未来 nn 天的生活。他每天都会去食堂,并且已经确定了接下来 nn 天中每一天将点的餐。食堂的价格保持不变,因此阿尔谢尼在第 ii 天将花费 cic_i 卢布。

市面上流通的货币包括 1 卢布硬币和 100 卢布纸币。目前,阿尔谢尼手中有 mm 枚硬币,以及数量充足的纸币(你可以假定他拥有无限多张纸币)。阿尔谢尼热爱现代科技,因此除食堂外,他处处使用信用卡;但食堂不接受银行卡支付,他必须以现金付款。

收银员总是要求学生“无需找零”地付款。然而,这并不总能实现;但阿尔谢尼希望尽量减小收银员的不满程度。收银员每天的不满程度由当天所找零钱中纸币与硬币的总数决定。具体而言,若收银员在第 ii 天向阿尔谢尼找回 xx 张纸币和硬币,则该天的不满程度为 x⋅wix \cdot w_i。收银员总是以最少数量的纸币和硬币进行找零,且始终拥有足够数量的纸币与硬币来完成这一操作。

“注意!愤怒的收银员”

阿尔谢尼希望以某种付款方式,使得 nn 天内收银员的总不满程度最小。请帮助他确定:在每一天他应如何付款!

注意:阿尔谢尼总有足够的钱付款,因为他拥有无限多张纸币。此外,阿尔谢尼可以在之后任意一天中使用之前某天找零所得的纸币或硬币。

输入格式

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 _c_1, _c_2, ..., c__n (1 ≤ c__i ≤ 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 _w_1, _w_2, ..., w__n (1 ≤ w__i ≤ 105) — the cashier's dissatisfaction coefficients for each of the following days.

第一行包含两个整数 nn 和 mm(1≤n≤1051 \leq n \leq 10^5,0≤m≤1090 \leq m \leq 10^9)—— 分别表示阿森尼计划安排行动的天数,以及他当前拥有的硬币数量。

第二行包含一个整数序列 c1,c2,…,cnc_1, c_2, \dots, c_n(1≤ci≤1051 \leq c_i \leq 10^5)—— 表示阿森尼在接下来每一天将要花费的卢布金额。

第三行包含一个整数序列 w1,w2,…,wnw_1, w_2, \dots, w_n(1≤wi≤1051 \leq w_i \leq 10^5)—— 表示收银员在接下来每一天的不满系数。

输出格式

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.

第一行输出一个整数——收银员可能的最小总不满值。

然后输出 nn 行,其中第 ii 行应包含两个数——Arseny 在第 ii 天食堂付款时应使用的纸币张数和硬币枚数。

当然,Arseny 每天付给收银员的总金额不得少于他当天计划花费的金额。同时,该金额也不得超过 10610^6 卢布:Arseny 从不随身携带大额现金。

若存在多个满足条件的答案,输出任意一个即可。

输入输出样例

  • 输入#1

    5 42
    117 71 150 243 200
    1 1 1 1 1

    输出#1

    79
    1 17
    1 0
    2 0
    2 43
    2 0
  • 输入#2

    3 0
    100 50 50
    1 3 2

    输出#2

    150
    1 0
    1 0
    0 50
  • 输入#3

    5 42
    117 71 150 243 200
    5 4 3 2 1

    输出#3

    230
    1 17
    1 0
    1 50
    3 0
    2 0

输入解题思路,AI测评打分。不知道怎么写?

首页