CF1178A.Prime Minister
入门
通过率:0%
时间限制:1.00s
内存限制:256MB
AC君温馨提醒
该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。
题目描述
Alice is the leader of the State Refactoring Party, and she is about to become the prime minister.
The elections have just taken place. There are n parties, numbered from 1 to n. The i-th party has received ai seats in the parliament.
Alice's party has number 1. In order to become the prime minister, she needs to build a coalition, consisting of her party and possibly some other parties. There are two conditions she needs to fulfil:
- The total number of seats of all parties in the coalition must be a strict majority of all the seats, i.e. it must have strictly more than half of the seats. For example, if the parliament has 200 (or 201) seats, then the majority is 101 or more seats.
- Alice's party must have at least 2 times more seats than any other party in the coalition. For example, to invite a party with 50 seats, Alice's party must have at least 100 seats.
For example, if n=4 and a=[51,25,99,25] (note that Alice'a party has 51 seats), then the following set [a1=51,a2=25,a4=25] can create a coalition since both conditions will be satisfied. However, the following sets will not create a coalition:
- [a2=25,a3=99,a4=25] since Alice's party is not there;
- [a1=51,a2=25] since coalition should have a strict majority;
- [a1=51,a2=25,a3=99] since Alice's party should have at least 2 times more seats than any other party in the coalition.
Alice does not have to minimise the number of parties in a coalition. If she wants, she can invite as many parties as she wants (as long as the conditions are satisfied). If Alice's party has enough people to create a coalition on her own, she can invite no parties.
Note that Alice can either invite a party as a whole or not at all. It is not possible to invite only some of the deputies (seats) from another party. In other words, if Alice invites a party, she invites all its deputies.
Find and print any suitable coalition.
爱丽丝是“国家重构党”的领袖,她即将成为总理。
选举刚刚结束。共有 n 个政党,编号从 1 到 n。第 i 个政党在议会中获得了 ai 个席位。
爱丽丝所在的政党编号为 1。为了成为总理,她需要组建一个联合政府,该联合政府由她的政党以及可能的其他若干政党组成。她必须满足以下两个条件:
- 联合政府中所有政党的席位总数必须超过议会总席位的一半(即严格多数)。例如,若议会共有 200(或 201)个席位,则多数席位数为 101 或更多。
- 爱丽丝所在政党在联合政府中的席位数,必须至少是联合政府中任何其他政党的席位数的 2 倍。例如,若要邀请一个拥有 50 个席位的政党,则爱丽丝所在政党必须至少拥有 100 个席位。
例如,若 n=4 且 a=[51,25,99,25](注意爱丽丝所在政党有 51 个席位),则集合 [a1=51,a2=25,a4=25] 可构成一个合法联合政府,因为两个条件均被满足。然而,以下集合无法构成联合政府:
- [a2=25,a3=99,a4=25]:因为爱丽丝所在政党未加入;
- [a1=51,a2=25]:因为联合政府席位总数未达到严格多数;
- [a1=51,a2=25,a3=99]:因为爱丽丝所在政党席位数(51)不足 a3=99 的 2 倍。
爱丽丝无需最小化联合政府所包含的政党数量。如果她愿意,她可以邀请任意多个政党(只要满足上述条件)。如果爱丽丝所在政党自身席位已足以单独构成联合政府,她也可以不邀请任何其他政党。
注意:爱丽丝只能以整体形式邀请某个政党,而不能只邀请其中一部分代表(席位)。换言之,一旦邀请某个政党,就必须接纳其全部席位。
请找出并输出任意一个满足条件的联合政府(即输出联合政府中各政党的编号)。
输入格式
The first line contains a single integer n (2≤n≤100) — the number of parties.
The second line contains n space separated integers a1,a2,…,an (1≤ai≤100) — the number of seats the i-th party has.
第一行包含一个整数 n(2≤n≤100)—— 政党的数量。
第二行包含 n 个用空格分隔的整数 a1,a2,…,an(1≤ai≤100)—— 第 i 个政党所拥有的席位数。
输出格式
If no coalition satisfying both conditions is possible, output a single line with an integer 0.
Otherwise, suppose there are k (1≤k≤n) parties in the coalition (Alice does not have to minimise the number of parties in a coalition), and their indices are c1,c2,…,ck (1≤ci≤n). Output two lines, first containing the integer k, and the second the space-separated indices c1,c2,…,ck.
You may print the parties in any order. Alice's party (number 1) must be on that list. If there are multiple solutions, you may print any of them.
如果不存在同时满足两个条件的联盟,则输出一行整数 0。
否则,假设联盟中包含 k(1≤k≤n)个政党(爱丽丝无需使联盟中的政党数量最小化),其编号为 c1,c2,…,ck(1≤ci≤n)。此时输出两行:第一行为整数 k,第二行为用空格分隔的编号 c1,c2,…,ck。
政党的输出顺序任意。爱丽丝所在的政党(编号 1)必须出现在该列表中。若存在多个解,可输出其中任意一个。
输入输出样例
输入#1
3 100 50 50
输出#1
2 1 2
输入#2
3 80 60 60
输出#2
0
输入#3
2 6 5
输出#3
1 1
输入#4
4 51 25 99 25
输出#4
3 1 2 4
说明/提示
In the first example, Alice picks the second party. Note that she can also pick the third party or both of them. However, she cannot become prime minister without any of them, because 100 is not a strict majority out of 200.
In the second example, there is no way of building a majority, as both other parties are too large to become a coalition partner.
In the third example, Alice already has the majority.
The fourth example is described in the problem statement.
在第一个例子中,Alice 选择了第二个政党。注意,她也可以选择第三个政党,或同时选择这两个政党。然而,若不与其中任一政党合作,她将无法成为总理,因为 100 票在总共 200 票中并不构成绝对多数。
在第二个例子中,不存在组建多数派的方案,因为其余两个政党规模均过大,无法成为联盟伙伴。
在第三个例子中,Alice 已经拥有多数席位。
第四个例子已在题目描述中给出。
输入解题思路,AI测评打分。不知道怎么写?