QOJ.ac

QOJ

Time Limit: 4 s Memory Limit: 32 MB Total points: 100

#16941. 手套

Statistics

在化学教授 Acidrain 房子的黑暗地下室里,有两个装有手套的抽屉——一个装有左手手套,另一个装有右手手套。每个抽屉里都有 $n$ 种不同颜色的手套。教授知道每个抽屉中每种颜色的手套各有多少只(相同颜色的手套在两个抽屉中的数量可能不同)。他也确定一定可以配出一双相同颜色的手套。

教授的实验只有在他使用相同颜色(具体哪种颜色无所谓)的手套时才能成功。因此,在每次实验之前,他都会去地下室从抽屉里拿手套,希望其中至少有一双相同颜色的手套。地下室非常黑暗,不离开地下室就无法辨认任何手套的颜色。教授非常讨厌去地下室超过一次(以防拿出来的手套无法配对),同时也讨厌带不必要的大量手套到实验室。

请编写一个程序:

  • 从标准输入读取颜色数量以及每个抽屉中每种颜色手套的数量;
  • 计算为了确保其中至少能配出一双相同颜色的手套,所必须拿取的手套的最小总数(需要确定从每个抽屉中具体拿取的手套数量);
  • 将结果写入标准输出。

输入格式

第一行包含一个正整数 $n$ ($1 \le n \le 20$),表示不同颜色的数量。

第二行包含 $n$ 个非负整数 $0 \le a_1, a_2, \dots, a_n \le 10^8$,其中 $a_i$ 表示左手手套抽屉中第 $i$ 种颜色手套的数量。

第三行包含 $n$ 个非负整数 $0 \le b_1, b_2, \dots, b_n \le 10^8$,其中 $b_i$ 表示右手手套抽屉中第 $i$ 种颜色手套的数量。

输出格式

第一行输出一个整数,表示必须从左手手套抽屉中拿取的手套数量。

第二行输出一个整数,表示必须从右手手套抽屉中拿取的手套数量。

这两个数量的和应当尽可能小。如果有多个正确答案,你的程序可以输出其中任意一个。

数据范围

对于 $40\%$ 的测试数据,满足 $n \le 4$ 且 $a_i, b_i \le 10$。

样例

输入样例 1

4
0 7 1 6
1 5 0 6

输出样例 1

2
8

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.