Codeforces 149C Division into Teams

来源:互联网 发布:上班时间 知乎 编辑:程序博客网 时间:2024/04/20 01:49

C. Division into Teams

time limit per test

2 seconds

memory limit per test

256 megabytes

input

standard input

output

standard output

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 (forexample, water the flowers).

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

Let's denote the number of players in the first team as x, thenumber of players in the second team asy, the individual numbers ofboys who play for the first team as pi and the individualnumbers of boys who play for the second team asqi. Division nboys 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 guaranteedthat a fair division into two teams always exists.

Input

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

Output

On the first line print an integer x — the number of boys playingfor the first team. On the second line printx integers — the individualnumbers of boys playing for the first team. On the third line print an integery— the number of boys playing for the second team, on the fourth line printyintegers — the individual numbers of boys playing for the second team. Don'tforget that you should fulfil all three conditions:x + y = n, |x - y| ≤ 1, and the condition that limitsthe 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 skillsare given in the input data. You are allowed to print individual numbers ofboys who belong to the same team in any order.

Examples

Input

3
1 2 1

Output

2
1 2
1
3

Input

5
2 3 3 1 1

Output

3
4 1 3
2
5 2

Note

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

 

 

 

题目大意:

         把一组人分为两对,需要满足三个条件

1 两队人的人数和为n

2两队人的人数的差值小于等于1

3两队人的技能和都近可能均等(每个人都有一个Ai表示足球技能),

差值要小于所有人中最大的那个

 

解题思路:

         只需要把每个人的技能值排个序,然后放入两个队列即可。

一边放一个。如果是奇数,那随意放入一个队列。

这样可以保证两队的技能差值最小

 

 

 

#include<iostream>#include<cstdio>#include<cstring>#include<algorithm>#include<functional>#include<queue>using namespace std;struct node{int index,value;}num[100005],tmp;bool cmp(struct node a,struct node b){return a.value<b.value;}int main(){queue<struct node> p,q;int n,x;int i,j,k;scanf("%d",&n);for(i=1;i<=n;i++){scanf("%d",&x);num[i].index=i;num[i].value=x;}sort(num+1,num+n+1,cmp);for(i=1;i<=n;i++){q.push(num[i]);i++;if(i>n)break;p.push(num[i]);}printf("%d\n",q.size());while(q.size()){tmp=q.front();printf("%d ",tmp.index);q.pop();}cout<<endl;printf("%d\n",p.size());while(p.size()){tmp=p.front();printf("%d ",tmp.index);p.pop();}}

原创粉丝点击