CF149C.Division into Teams

普及/提高-

通过率:0%

时间限制:1.00s

内存限制:256MB

AC君温馨提醒

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

题目描述

Petya loves football very much, especially when his parents aren't home. Each morning he comes to the yard, gathers his friends and they play all day. From time to time they have a break to have some food or do some chores (for example, water the flowers).

The key in football is to divide into teams fairly before the game begins. There are n boys playing football in the yard (including Petya), each boy's football playing skill is expressed with a non-negative characteristic a__i (the larger it is, the better the boy plays).

Let's denote the number of players in the first team as x, the number of players in the second team as y, the individual numbers of boys who play for the first team as p__i and the individual numbers of boys who play for the second team as q__i. Division n boys into two teams is considered fair if three conditions are fulfilled:

  • Each boy plays for exactly one team (x + y = n).

  • The sizes of teams differ in no more than one (|x - y| ≤ 1).

  • The total football playing skills for two teams differ in no more than by the value of skill the best player in the yard has. More formally:

Your task is to help guys divide into two teams fairly. It is guaranteed that a fair division into two teams always exists.

佩佳非常喜欢足球,尤其是当他的父母不在家时。每天早晨,他都会来到院子里,召集朋友们一起玩上一整天。期间,他们偶尔会休息一下,吃点东西或做些杂事(例如给花浇水)。

足球的关键在于比赛开始前公平地分队。目前院子里共有 $ n $ 名男孩在踢足球(包括佩佳),每名男孩的足球水平用一个非负整数特征值 $ a_i $ 表示(数值越大,球技越好)。

记第一支队伍的人数为 $ x $,第二支队伍的人数为 $ y $;第一支队伍中各球员的编号为 $ p_i $,第二支队伍中各球员的编号为 $ q_i $。将这 $ n $ 名男孩划分为两支队伍被称为公平划分,当且仅当下列三个条件同时满足:

  • 每个男孩恰好属于一支队伍(即 $ x + y = n $);

  • 两支队伍的人数之差至多为 $ 1 $(即 $ |x - y| \leq 1 $);

  • 两支队伍的总足球水平之差不超过院子里水平最高的球员的水平值。更严格地表述为:

你的任务是帮助这群孩子公平地分成两支队伍。题目保证:一定存在一种公平的两队划分方式。

输入格式

The first line contains the only integer n (2 ≤ n ≤ 105) which represents the number of guys in the yard. The next line contains n positive space-separated integers, a__i (1 ≤ a__i ≤ 104), the i-th number represents the i-th boy's playing skills.

第一行包含唯一一个整数 nn(2≤n≤1052 \leq n \leq 10^5),表示院子里的人数。
第二行包含 nn 个用空格分隔的正整数 aia_i(1≤ai≤1041 \leq a_i \leq 10^4),其中第 ii 个数表示第 ii 个男孩的游戏技能值。

输出格式

On the first line print an integer x — the number of boys playing for the first team. On the second line print x integers — the individual numbers of boys playing for the first team. On the third line print an integer y — the number of boys playing for the second team, on the fourth line print y integers — the individual numbers of boys playing for the second team. Don't forget that you should fulfil all three conditions: x + y = n, |x - y| ≤ 1, and the condition that limits the total skills.

If there are multiple ways to solve the problem, print any of them.

The boys are numbered starting from one in the order in which their skills are given in the input data. You are allowed to print individual numbers of boys who belong to the same team in any order.

第一行输出一个整数 xx —— 第一队的男生人数。
第二行输出 xx 个整数 —— 第一队男生各自的编号。
第三行输出一个整数 yy —— 第二队的男生人数,第四行输出 yy 个整数 —— 第二队男生各自的编号。
请勿忘记需同时满足以下三个条件:x+y=nx + y = n、∣x−y∣≤1|x - y| \leq 1,以及限制总技能值的条件。

若存在多种解法,输出任意一种即可。

男生编号从 11 开始,按输入数据中给出其技能值的顺序依次编号。同一队内男生的编号可按任意顺序输出。

输入输出样例

  • 输入#1

    3
    1 2 1

    输出#1

    2
    1 2 
    1
    3
  • 输入#2

    5
    2 3 3 1 1

    输出#2

    3
    4 1 3 
    2
    5 2

说明/提示

Let's consider the first sample test. There we send the first and the second boy to the first team and the third boy to the second team. Let's check all three conditions of a fair division. The first limitation is fulfilled (all boys play), the second limitation on the sizes of groups (|2 - 1| = 1 ≤ 1) is fulfilled, the third limitation on the difference in skills ((2 + 1) - (1) = 2 ≤ 2) is fulfilled.

我们来考虑第一个样例测试。在该测试中,我们将第一个和第二个男孩分配到第一支队伍,第三个男孩分配到第二支队伍。我们来验证公平划分的全部三个条件:
第一个限制条件满足(所有男孩都参与比赛);
第二个关于队伍人数规模的限制条件满足(|2 − 1| = 1 ≤ 1);
第三个关于技能总和之差的限制条件满足((2 + 1) − (1) = 2 ≤ 2)。

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

首页