CF767E.Change-free

普及/提高-

通过率:0%

AC君温馨提醒

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

题目描述

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

There are 11 -ruble coins and 100100 -ruble notes in circulation. At this moment, Arseny has mm 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 xx notes and coins on the ii -th day, his dissatisfaction for this day equals xwix·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 nn days would be as small as possible. Help him to find out how he needs to pay in each of the nn 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.

输入格式

The first line contains two integers nn and mm ( 1<=n<=1051<=n<=10^{5} , 0<=m<=1090<=m<=10^{9} ) — 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,...,cnc_{1},c_{2},...,c_{n} ( 1<=ci<=1051<=c_{i}<=10^{5} ) — 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,...,wnw_{1},w_{2},...,w_{n} ( 1<=wi<=1051<=w_{i}<=10^{5} ) — the cashier's dissatisfaction coefficients for each of the following days.

输出格式

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

Then print nn lines, the ii -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 ii -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 10610^{6} rubles: Arseny never carries large sums of money with him.

If there are multiple answers, print any of them.

输入输出样例

  • 输入#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
    
首页