AT_abc473_b.Old Maid

入门

通过率:0%

时间限制:2.00s

内存限制:1024MB

AC君温馨提醒

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

题目描述

Takahashi currently has NN cards. The ii-th (1≤i≤N)(1\le i\le N) card has the integer AiA _ i written on it.

He repeats the following operation as many times as possible.

  • Choose two different cards with the same integer written on them, and eat those two cards. The eaten cards are permanently removed and cannot be chosen in subsequent operations.

Find the sum of the integers written on the cards that remain when the operation can no longer be performed.

高桥目前有 NN 张卡片。第 ii 张卡片(1≤i≤N1\le i\le N)上写有一个整数 AiA_i。

他尽可能多地重复以下操作:

  • 选择两张写有相同整数的不同卡片,并吃掉这两张卡片。被吃掉的卡片将被永久移除,后续操作中无法再被选中。

当无法再执行该操作时,求剩余卡片上所写整数的总和。

输入格式

The input is given from Standard Input in the following format:

NN
A1A _ 1 A2A _ 2 ⋯\cdots ANA _ N

输入从标准输入中按以下格式给出:

NN
A1A _ 1 A2A _ 2 ⋯\cdots ANA _ N

输出格式

Output the sum of the integers written on the remaining cards.

输出剩余卡片上整数的总和。

输入输出样例

  • 输入#1

    8
    2 7 1 8 2 8 1 8

    输出#1

    15
  • 输入#2

    5
    1 2 3 4 5

    输出#2

    15
  • 输入#3

    15
    58 97 74 16 97 74 97 16 51 52 58 52 74 32 43

    输出#3

    297

说明/提示

Sample 1 Explanation:
For example, Takahashi operates as follows.

  1. The fourth card and sixth card both have 88 written on them, so he chooses them and eats them.
  2. The first card and fifth card both have 22 written on them, so he chooses them and eats them.
  3. The third card and seventh card both have 11 written on them, so he chooses them and eats them.

Thus, the sum of the integers written on the remaining cards is 7+8=157+8=15.

Note that there are three cards with 88 written on them, so once two of them are eaten, the remaining one cannot be eaten.

Sample 2 Explanation:
It is possible that Takahashi cannot perform the operation even once.

Constraints

  • 1≤N≤1001\le N\le100
  • 1≤Ai≤100 (1≤i≤N)1\le A _ i\le100\ (1\le i\le N)
  • All input values are integers.

样例 1 解释:
例如,高桥的操作过程如下:

  1. 第四张卡片和第六张卡片上均写有数字 88,因此他选择这两张卡片并吃掉它们。
  2. 第一张卡片和第五张卡片上均写有数字 22,因此他选择这两张卡片并吃掉它们。
  3. 第三张卡片和第七张卡片上均写有数字 11,因此他选择这两张卡片并吃掉它们。

因此,剩余卡片上所写整数的总和为 7+8=157+8=15。

注意:共有三张卡片上写有数字 88,因此当其中两张被吃掉后,剩下的一张便无法再被吃掉。

样例 2 解释:
高桥可能一次操作都无法执行。

约束条件

  • 1≤N≤1001\le N\le100
  • 1≤Ai≤100 (1≤i≤N)1\le A _ i\le100\ (1\le i\le N)
  • 所有输入值均为整数。

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

首页