QOJ.ac

QOJ

実行時間制限: 2.5 s メモリ制限: 128 MB 満点: 100

#11585. 洗衣

統計

几位朋友决定一起洗衣服。他们非常爱整洁,所以每天每位朋友都要穿一双干净的袜子和一件干净的衬衫。朋友们把所有脏袜子和衬衫都放进了洗衣机。现在,他们开始计划如何晾晒衣物。为了井然有序,他们决定:

  • 每只袜子都要用一个衣夹固定在绳子上;
  • 每件衬衫都要用三个衣夹固定;
  • 同一个人的所有袜子必须使用同一种颜色的衣夹;
  • 同一个人的所有衬衫必须使用同一种颜色的衣夹;
  • 属于不同人的衣物不得使用同一种颜色的衣夹;
  • 除此之外,他们希望使用的衣夹颜色种类尽可能少。

现在,他们把所有的衣夹都撒在地板上,并数出了每种颜色的衣夹数量。不幸的是,他们无法确定每个人应该使用哪些颜色。请编写一个程序来帮助他们解决这个问题。

输入格式

第一行包含两个整数 $n$ 和 $k$ ($2 \le n, k \le 1\,000\,000$),分别表示朋友的人数和可用的衣夹颜色数量。第二行包含 $n$ 个整数 $d_1, d_2, \dots, d_n$,表示每位朋友收集脏衣物的天数 ($1 \le d_i \le 1\,000\,000$)。第三行包含 $k$ 个整数 $l_1, l_2, \dots, l_k$,表示相应颜色的衣夹数量 ($1 \le l_i \le 4\,000\,000$)。

输出格式

你的程序应输出晾晒所有衣物所需的最少衣夹颜色数量。如果无法按照要求晾晒所有衣物,你的程序应输出一个单词 NIE(即波兰语中的“不”)。

样例

输入 1

2 4
3 4
20 10 8 10

输出 1

3

输入 2

3 8
5 4 3
14 14 14 14 14 14 14 14

输出 2

NIE

说明

第一个样例的解释:第一位朋友的袜子需要 6 个衣夹,衬衫需要 8 个衣夹。第二位朋友的袜子需要 8 个衣夹,衬衫需要 12 个衣夹。第二位朋友应该同时使用第一种颜色的衣夹来晾晒她的袜子和衬衫。然后,第一位朋友可以使用例如第二种和第四种颜色的衣夹。

Discussions

About Discussions

The discussion section is only for posting: General Discussions (problem-solving strategies, alternative approaches), and Off-topic conversations.

This is NOT for reporting issues! If you want to report bugs or errors, please use the Issues section below.

Open Discussions 0
No discussions in this category.

Issues

About Issues

If you find any issues with the problem (statement, scoring, time/memory limits, test cases, etc.), you may submit an issue here. A problem moderator will review your issue.

Guidelines:

  1. This is not a place to publish discussions, editorials, or requests to debug your code. Issues are only visible to you and problem moderators.
  2. Do not submit duplicated issues.
  3. Issues must be filed in English or Chinese only.
Active Issues 0
No issues in this category.
Closed/Resolved Issues 0
No issues in this category.