A11968 | Vitamins
时间限制1s
内存限制256MB
通过 / 提交0/0
题目描述
Berland shop sells $n$ kinds of juices. Each juice has its price $c_i$ . Each juice includes some set of vitamins in it. There are three types of vitamins: vitamin "A", vitamin "B" and vitamin "C". Each juice can contain one, two or all three types of vitamins in it.
Petya knows that he needs all three types of vitamins to stay healthy. What is the minimum total price of juices that Petya has to buy to obtain all three vitamins? Petya obtains some vitamin if he buys at least one juice containing it and drinks it.
Petya knows that he needs all three types of vitamins to stay healthy. What is the minimum total price of juices that Petya has to buy to obtain all three vitamins? Petya obtains some vitamin if he buys at least one juice containing it and drinks it.
输入格式
The first line contains a single integer $n$ $(1 \le n \le 1\,000)$ — the number of juices.
Each of the next $n$ lines contains an integer $c_i$ $(1 \le c_i \le 100\,000)$ and a string $s_i$ — the price of the $i$ -th juice and the vitamins it contains. String $s_i$ contains from $1$ to $3$ characters, and the only possible characters are "A", "B" and "C". It is guaranteed that each letter appears no more than once in each string $s_i$ . The order of letters in strings $s_i$ is arbitrary.
Each of the next $n$ lines contains an integer $c_i$ $(1 \le c_i \le 100\,000)$ and a string $s_i$ — the price of the $i$ -th juice and the vitamins it contains. String $s_i$ contains from $1$ to $3$ characters, and the only possible characters are "A", "B" and "C". It is guaranteed that each letter appears no more than once in each string $s_i$ . The order of letters in strings $s_i$ is arbitrary.
输出格式
Print -1 if there is no way to obtain all three vitamins. Otherwise print the minimum total price of juices that Petya has to buy to obtain all three vitamins.
输入输出样例
输入 #1
4 5 C 6 B 16 BAC 4 A
输出 #1
15
输入 #2
2 10 AB 15 BA
输出 #2
-1
输入 #3
5 10 A 9 BC 11 CA 4 A 5 B
输出 #3
13
输入 #4
6 100 A 355 BCA 150 BC 160 AC 180 B 190 CA
输出 #4
250
输入 #5
2 5 BA 11 CB
输出 #5
16
In the first example Petya buys the first, the second and the fourth juice. He spends $5 + 6 + 4 = 15$ and obtains all three vitamins. He can also buy just the third juice and obtain three vitamins, but its cost is $16$ , which isn't optimal.
In the second example Petya can't obtain all three vitamins, as no juice contains vitamin "C".
In the second example Petya can't obtain all three vitamins, as no juice contains vitamin "C".
C++ 编辑器
输入
输出
可保存默认模板;新题优先使用已保存模板。
当前快捷键仅展示,暂不支持修改。
- 撤销
Ctrl / ⌘ + Z - 重做
Ctrl / ⌘ + Y - 查找
Ctrl / ⌘ + F - 全选
Ctrl / ⌘ + A - 复制
Ctrl / ⌘ + C - 剪切
Ctrl / ⌘ + X - 粘贴
Ctrl / ⌘ + V - 自动排版
工具栏排版按钮 - 草稿保存
编辑时自动保存到本机
历史
提交记录
状态说明时间源码
AI
作答助手
你好,我是作答助手。可以问思路、复杂度、样例含义或代码报错原因;不会直接给出完整 AC 代码。
确定要清空代码吗?
提交通过
评测结果:Accepted