CF609D.Gadgets for dollars and pounds

普及/提高-

通过率:0%

AC君温馨提醒

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

题目描述

Nura wants to buy kk gadgets. She has only ss burles for that. She can buy each gadget for dollars or for pounds. So each gadget is selling only for some type of currency. The type of currency and the cost in that currency are not changing.

Nura can buy gadgets for nn days. For each day you know the exchange rates of dollar and pound, so you know the cost of conversion burles to dollars or to pounds.

Each day (from 11 to nn ) Nura can buy some gadgets by current exchange rate. Each day she can buy any gadgets she wants, but each gadget can be bought no more than once during nn days.

Help Nura to find the minimum day index when she will have kk gadgets. Nura always pays with burles, which are converted according to the exchange rate of the purchase day. Nura can't buy dollars or pounds, she always stores only burles. Gadgets are numbered with integers from 11 to mm in order of their appearing in input.

输入格式

First line contains four integers n,m,k,sn,m,k,s ( 1<=n<=2105,1<=k<=m<=2105,1<=s<=1091<=n<=2·10^{5},1<=k<=m<=2·10^{5},1<=s<=10^{9} ) — number of days, total number and required number of gadgets, number of burles Nura has.

Second line contains nn integers aia_{i} ( 1<=ai<=1061<=a_{i}<=10^{6} ) — the cost of one dollar in burles on ii -th day.

Third line contains nn integers bib_{i} ( 1<=bi<=1061<=b_{i}<=10^{6} ) — the cost of one pound in burles on ii -th day.

Each of the next mm lines contains two integers ti,cit_{i},c_{i} ( 1<=ti<=2,1<=ci<=1061<=t_{i}<=2,1<=c_{i}<=10^{6} ) — type of the gadget and it's cost. For the gadgets of the first type cost is specified in dollars. For the gadgets of the second type cost is specified in pounds.

输出格式

If Nura can't buy kk gadgets print the only line with the number -1.

Otherwise the first line should contain integer dd — the minimum day index, when Nura will have kk gadgets. On each of the next kk lines print two integers qi,diq_{i},d_{i} — the number of gadget and the day gadget should be bought. All values qiq_{i} should be different, but the values did_{i} can coincide (so Nura can buy several gadgets at one day). The days are numbered from 11 to nn .

In case there are multiple possible solutions, print any of them.

输入输出样例

  • 输入#1

    5 4 2 2
    1 2 3 2 1
    3 2 1 2 3
    1 1
    2 1
    1 2
    2 2
    

    输出#1

    3
    1 1
    2 3
    
  • 输入#2

    4 3 2 200
    69 70 71 72
    104 105 106 107
    1 1
    2 2
    1 2
    

    输出#2

    -1
    
  • 输入#3

    4 3 1 1000000000
    900000 910000 940000 990000
    990000 999000 999900 999990
    1 87654
    2 76543
    1 65432
    

    输出#3

    -1
    
首页