CF159E.Zebra Tower
普及+/提高
通过率:0%
时间限制:1.50s
内存限制:256MB
AC君温馨提醒
该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。
题目描述
Little Janet likes playing with cubes. Actually, she likes to play with anything whatsoever, cubes or tesseracts, as long as they are multicolored. Each cube is described by two parameters — color c__i and size s__i. A Zebra Tower is a tower that consists of cubes of exactly two colors. Besides, the colors of the cubes in the tower must alternate (colors of adjacent cubes must differ). The Zebra Tower should have at least two cubes. There are no other limitations. The figure below shows an example of a Zebra Tower.

A Zebra Tower's height is the sum of sizes of all cubes that form the tower. Help little Janet build the Zebra Tower of the maximum possible height, using the available cubes.
小珍妮特喜欢玩立方体。实际上,她喜欢玩任何东西,无论是立方体还是四维超立方体(tesseract),只要它们是多色的即可。每个立方体由两个参数描述:颜色 ci 和尺寸 si。斑马塔(Zebra Tower)是由恰好两种颜色的立方体构成的塔;此外,塔中立方体的颜色必须交替出现(即相邻立方体的颜色必须不同)。斑马塔至少需要包含两个立方体,除此之外没有其他限制。下图展示了一个斑马塔的示例:

斑马塔的高度定义为组成该塔的所有立方体的尺寸之和。请帮助小珍妮特利用手头现有的立方体,搭建出高度尽可能大的斑马塔。
输入格式
The first line contains an integer n (2 ≤ n ≤ 105) — the number of cubes. Next n lines contain the descriptions of the cubes, one description per line. A cube description consists of two space-separated integers c__i and s__i (1 ≤ c__i, s__i ≤ 109) — the i-th cube's color and size, correspondingly. It is guaranteed that there are at least two cubes of different colors.
第一行包含一个整数 n(2≤n≤105)——立方体的数量。接下来的 n 行每行描述一个立方体。每个立方体的描述由两个以空格分隔的整数 ci 和 si(1≤ci,si≤109)组成,分别表示第 i 个立方体的颜色和尺寸。保证至少存在两个不同颜色的立方体。
输出格式
Print the description of the Zebra Tower of the maximum height in the following form. In the first line print the tower's height, in the second line print the number of cubes that form the tower, and in the third line print the space-separated indices of cubes in the order in which they follow in the tower from the bottom to the top. Assume that the cubes are numbered from 1 to n in the order in which they were given in the input.
If there are several existing Zebra Towers with maximum heights, it is allowed to print any of them.
Please do not use the %lld specificator to read or write 64-bit integers in С++. It is preferred to use the cin, cout streams or the %I64d specificator.
以如下格式输出最高“斑马塔”的描述:第一行输出塔的高度,第二行输出构成该塔的立方体数量,第三行输出从塔底到塔顶各立方体的编号(用空格分隔)。假设立方体按输入顺序从 1 到 n 编号。
若存在多个具有最大高度的“斑马塔”,输出其中任意一个即可。
在 C++ 中,请勿使用 %lld 格式说明符读写 64 位整数;推荐使用 cin/cout 流,或 %I64d 格式说明符。
输入输出样例
输入#1
4 1 2 1 3 2 4 3 3
输出#1
9 3 2 3 1
输入#2
2 1 1 2 1
输出#2
2 2 2 1
输入解题思路,AI测评打分。不知道怎么写?