CF1195A.Drinks Choosing
入门
通过率:0%
时间限制:2.00s
内存限制:256MB
AC君温馨提醒
该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。
题目描述
Old timers of Summer Informatics School can remember previous camps in which each student was given a drink of his choice on the vechorka (late-evening meal). Or may be the story was more complicated?
There are n students living in a building, and for each of them the favorite drink ai is known. So you know n integers a1,a2,…,an, where ai (1≤ai≤k) is the type of the favorite drink of the i-th student. The drink types are numbered from 1 to k.
There are infinite number of drink sets. Each set consists of exactly two portions of the same drink. In other words, there are k types of drink sets, the j-th type contains two portions of the drink j. The available number of sets of each of the k types is infinite.
You know that students will receive the minimum possible number of sets to give all students exactly one drink. Obviously, the number of sets will be exactly ⌈2n⌉, where ⌈x⌉ is x rounded up.
After students receive the sets, they will distribute their portions by their choice: each student will get exactly one portion. Note, that if n is odd then one portion will remain unused and the students' teacher will drink it.
What is the maximum number of students that can get their favorite drink if ⌈2n⌉ sets will be chosen optimally and students will distribute portions between themselves optimally?
夏季信息学学校的老学员们可能还记得往届夏令营中,在晚间加餐(vechorka)时,每位学生都能得到自己选择的饮料。但也许这个故事更为复杂?
一栋宿舍楼里住着 n 名学生,已知每名学生最喜爱的饮料种类 ai。因此,你得到了 n 个整数 a1,a2,…,an,其中 ai(1≤ai≤k)表示第 i 名学生最喜爱的饮料种类。饮料种类编号为 1 至 k。
饮料组合包的数量是无限的。每个组合包恰好包含两份同一种类的饮料。换言之,共有 k 种饮料组合包,第 j 种组合包包含两份第 j 种饮料。这 k 种组合包各自的可用数量均为无限。
已知学生们将领取最少可能数量的组合包,使得每位学生恰好获得一份饮料。显然,所需组合包总数恰好为 ⌈2n⌉,其中 ⌈x⌉ 表示对 x 向上取整。
在领取组合包后,学生们将自行分配其中的饮料份量:每位学生恰好获得一份。注意,若 n 为奇数,则会剩余一份饮料,由学生的老师饮用。
若以最优方式选取 ⌈2n⌉ 个组合包,并且学生们也以最优方式在彼此间分配这些饮料份量,那么最多有多少名学生能获得自己最喜爱的饮料?
输入格式
The first line of the input contains two integers n and k (1≤n,k≤1000) — the number of students in the building and the number of different drinks.
The next n lines contain student's favorite drinks. The i-th line contains a single integer from 1 to k — the type of the favorite drink of the i-th student.
输入的第一行包含两个整数 n 和 k(1≤n,k≤1000)—— 分别表示大楼中学生的数量以及不同饮料的种类数。
接下来的 n 行描述每位学生最喜爱的饮料。第 i 行包含一个从 1 到 k 的整数——表示第 i 位学生最喜爱的饮料类型。
输出格式
Print exactly one integer — the maximum number of students that can get a favorite drink.
输出一个整数——能够获得最喜欢饮料的学生的最大人数。
输入输出样例
输入#1
5 3 1 3 1 1 2
输出#1
4
输入#2
10 3 2 1 3 2 3 3 1 3 1 2
输出#2
9
说明/提示
In the first example, students could choose three sets with drinks 1, 1 and 2 (so they will have two sets with two drinks of the type 1 each and one set with two drinks of the type 2, so portions will be 1,1,1,1,2,2). This way all students except the second one will get their favorite drinks.
Another possible answer is sets with drinks 1, 2 and 3. In this case the portions will be 1,1,2,2,3,3. Then all the students except one will gain their favorite drinks. The only student that will not gain the favorite drink will be a student with ai=1 (i.e. the first, the third or the fourth).
在第一个例子中,学生可以选择三组饮品,分别为 1、1 和 2(即:两组各含两份类型 1 的饮品,一组含两份类型 2 的饮品,因此饮品份数序列为 1,1,1,1,2,2)。这样,除第二位学生外,其余所有学生都将获得其最喜爱的饮品。
另一种可行方案是选择饮品为 1、2 和 3 的三组。此时饮品份数序列为 1,1,2,2,3,3。在这种情况下,除一位学生外,其余所有学生都将获得其最喜爱的饮品;唯一无法获得最喜爱饮品的学生是满足 ai=1 的那位(即第一位、第三位或第四位学生)。
输入解题思路,AI测评打分。不知道怎么写?