CF767D.Cartons of milk

提高+/省选-

通过率:0%

时间限制:2.00s

内存限制:256MB

AC君温馨提醒

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

题目描述

Olya likes milk very much. She drinks k cartons of milk each day if she has at least k and drinks all of them if she doesn't. But there's an issue — expiration dates. Each carton has a date after which you can't drink it (you still can drink it exactly at the date written on the carton). Due to this, if Olya's fridge contains a carton past its expiry date, she throws it away.

Olya hates throwing out cartons, so when she drinks a carton, she chooses the one which expires the fastest. It's easy to understand that this strategy minimizes the amount of cartons thrown out and lets her avoid it if it's even possible.

Milk. Best before: 20.02.2017.

The main issue Olya has is the one of buying new cartons. Currently, there are n cartons of milk in Olya's fridge, for each one an expiration date is known (how soon does it expire, measured in days). In the shop that Olya visited there are m cartons, and the expiration date is known for each of those cartons as well.

Find the maximum number of cartons Olya can buy so that she wouldn't have to throw away any cartons. Assume that Olya drank no cartons today.

奥莉娅非常喜欢喝牛奶。如果冰箱中至少有 kk 盒牛奶,她每天就喝 kk 盒;否则,她就把所有剩下的牛奶全部喝完。但这里存在一个问题——保质期。每盒牛奶上都标有一个过期日期,过了该日期便不能再饮用(但在所标注的日期当天仍可饮用)。因此,如果奥莉娅的冰箱中有一盒牛奶已超过其保质期,她就会将其丢弃。

奥莉娅非常讨厌丢弃牛奶,因此每当她要喝一盒牛奶时,总是优先选择保质期最临近(即最早过期)的那一盒。不难理解,这种策略能最小化被丢弃的牛奶盒数,并且只要存在一种方案避免丢弃,该策略就一定能实现。

牛奶。最佳食用日期:2017年2月20日。

奥莉娅目前面临的主要问题是购买新牛奶。当前,她的冰箱中有 nn 盒牛奶,每盒的保质期(以距离今天的天数表示)均已知。她所去的商店里有 mm 盒牛奶,每盒的保质期也均已知。

请找出奥莉娅最多可以购买多少盒牛奶,使得她在此后无需丢弃任何一盒牛奶。假设奥莉娅今天尚未饮用任何牛奶。

输入格式

In the first line there are three integers n, m, k (1 ≤ n, m ≤ 106, 1 ≤ k ≤ n + m) — the amount of cartons in Olya's fridge, the amount of cartons in the shop and the number of cartons Olya drinks each day.

In the second line there are n integers _f_1, _f_2, ..., f__n (0 ≤ f__i ≤ 107) — expiration dates of the cartons in Olya's fridge. The expiration date is expressed by the number of days the drinking of this carton can be delayed. For example, a 0 expiration date means it must be drunk today, 1 — no later than tomorrow, etc.

In the third line there are m integers _s_1, _s_2, ..., s__m (0 ≤ s__i ≤ 107) — expiration dates of the cartons in the shop in a similar format.

第一行包含三个整数 nn、mm、kk(1≤n,m≤1061 \leq n, m \leq 10^6,1≤k≤n+m1 \leq k \leq n + m)——分别表示奥莉娅冰箱中的纸盒数量、商店中的纸盒数量,以及奥莉娅每天饮用的纸盒数量。

第二行包含 nn 个整数 f1, f2, …, fnf_1,\ f_2,\ \dots,\ f_n(0≤fi≤1070 \leq f_i \leq 10^7)——表示冰箱中各纸盒的保质期。保质期以“该纸盒最迟可延迟饮用的天数”来表示。例如,保质期为 00 表示必须在当天饮用,为 11 表示最迟在明天饮用,依此类推。

第三行包含 mm 个整数 s1, s2, …, sms_1,\ s_2,\ \dots,\ s_m(0≤si≤1070 \leq s_i \leq 10^7)——以相同格式表示商店中各纸盒的保质期。

输出格式

If there's no way for Olya to drink the cartons she already has in her fridge, print -1.

Otherwise, in the first line print the maximum number x of cartons which Olya can buy so that she wouldn't have to throw a carton away. The next line should contain exactly x integers — the numbers of the cartons that should be bought (cartons are numbered in an order in which they are written in the input, starting with 1). Numbers should not repeat, but can be in arbitrary order. If there are multiple correct answers, print any of them.

如果奥莉娅无法喝掉她冰箱中已有的纸盒装饮料,则输出 -1。

否则,第一行输出奥莉娅最多可以购买的纸盒装饮料数量 xx,使得她无需丢弃任何一盒饮料。第二行应恰好包含 xx 个整数——即应购买的纸盒装饮料的编号(纸盒按输入中的顺序编号,从 1 开始)。这些编号不能重复,但可以以任意顺序排列。若存在多个正确答案,输出其中任意一个即可。

输入输出样例

  • 输入#1

    3 6 2
    1 0 1
    2 0 2 0 0 2

    输出#1

    3
    1 2 3
  • 输入#2

    3 1 2
    0 0 0
    1

    输出#2

    -1
  • 输入#3

    2 1 2
    0 1
    0

    输出#3

    1
    1

说明/提示

In the first example k = 2 and Olya has three cartons with expiry dates 0, 1 and 1 (they expire today, tomorrow and tomorrow), and the shop has 3 cartons with expiry date 0 and 3 cartons with expiry date 2. Olya can buy three cartons, for example, one with the expiry date 0 and two with expiry date 2.

In the second example all three cartons Olya owns expire today and it means she would have to throw packets away regardless of whether she buys an extra one or not.

In the third example Olya would drink k = 2 cartons today (one she alreay has in her fridge and one from the shop) and the remaining one tomorrow.

在第一个例子中,k=2k = 2,Olya 拥有三盒牛奶,其保质期分别为 00、11 和 11(即分别于今天、明天和明天过期),而商店中有 33 盒保质期为 00 的牛奶和 33 盒保质期为 22 的牛奶。Olya 可以购买三盒牛奶,例如:一盒保质期为 00 的,以及两盒保质期为 22 的。

在第二个例子中,Olya 拥有的全部三盒牛奶均于今天过期,这意味着无论她是否额外购买一盒,都不得不丢弃部分牛奶。

在第三个例子中,Olya 今天将饮用 k=2k = 2 盒牛奶(一盒是她冰箱里已有的,另一盒来自商店),剩余的一盒则留到明天饮用。

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

首页