Codeforces Round #410 (Div. 2) D. Mike and distribution

本文介绍了一个关于从两个整数序列中选取特定子集的问题,以确保所选元素的两倍总和超过原序列总和。通过一种二维贪心算法解决了这一问题,并提供了实现代码。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

D. Mike and distribution
time limit per test
2 seconds
memory limit per test
256 megabytes
input
standard input
output
standard output

Mike has always been thinking about the harshness of social inequality. He's so obsessed with it that sometimes it even affects him while solving problems. At the moment, Mike has two sequences of positive integers A = [a1, a2, ..., an] and B = [b1, b2, ..., bn] of length neach which he uses to ask people some quite peculiar questions.

To test you on how good are you at spotting inequality in life, he wants you to find an "unfair" subset of the original sequence. To be more precise, he wants you to select k numbers P = [p1, p2, ..., pk] such that 1 ≤ pi ≤ n for 1 ≤ i ≤ k and elements in P are distinct. SequenceP will represent indices of elements that you'll select from both sequences. He calls such a subset P "unfair" if and only if the following conditions are satisfied: 2·(ap1 + ... + apk) is greater than the sum of all elements from sequence A, and 2·(bp1 + ... + bpk) is greater than the sum of all elements from the sequence B. Also, k should be smaller or equal to  because it will be to easy to find sequence P if he allowed you to select too many elements!

Mike guarantees you that a solution will always exist given the conditions described above, so please help him satisfy his curiosity!

Input

The first line contains integer n (1 ≤ n ≤ 105) — the number of elements in the sequences.

On the second line there are n space-separated integers a1, ..., an (1 ≤ ai ≤ 109) — elements of sequence A.

On the third line there are also n space-separated integers b1, ..., bn (1 ≤ bi ≤ 109) — elements of sequence B.

Output

On the first line output an integer k which represents the size of the found subset. k should be less or equal to .

On the next line print k integers p1, p2, ..., pk (1 ≤ pi ≤ n) — the elements of sequence P. You can print the numbers in any order you want. Elements in sequence P should be distinct.

Example
input
5
8 7 4 8 3
4 2 5 3 7
output
3
1 4 5

题意:给你两个长度为n的数组a,b,让你从中选择n/2+1个下标,使得对于每个数组,选择的元素之和的2倍大于整个数组的元素之和。


思路(二维贪心,先让一维有序):先把下标按a数组的大小从大到小排列,把第一个选上,然后接下来两个两个为一组,选择b数组值较大的那个下标,最后如果n是偶数,则还要把最后一个也选上。


#include<cstdio>
#include<algorithm>
using namespace std;

int n,k;
struct node
{
	int num;
	int id;
} a[100005],b[100005];

int ans[100005];

int cmp(node a,node b)
{
	return a.num>b.num;
}

int main()
{
	scanf("%d",&n);
	for(int i=0; i<n; i++)
	{
		scanf("%d",&a[i].num);
		a[i].id=i;
	}
	for(int i=0; i<n; i++)
	{
		scanf("%d",&b[i].num);
		b[i].id=i;
	}	
	sort(a,a+n,cmp);
	k=n/2+1;
	ans[0]=a[0].id+1;
	int j=1;
	for(int i=1; i+1<n; i=i+2)
	{
		if(b[a[i].id].num>b[a[i+1].id].num)
			ans[j]=a[i].id+1;
		else
			ans[j]=a[i+1].id+1;
		j++;
	}
	printf("%d\n",k);
	if(!(n&1))
	  ans[j]=a[n-1].id+1;
	for(int i=0;i<k;i++)
	   printf("%d ",ans[i]);
}






内容概要:本文探讨了在MATLAB/SimuLink环境中进行三相STATCOM(静态同步补偿器)无功补偿的技术方法及其仿真过程。首先介绍了STATCOM作为无功功率补偿装置的工作原理,即通过调节交流电压的幅值和相位来实现对无功功率的有效管理。接着详细描述了在MATLAB/SimuLink平台下构建三相STATCOM仿真模型的具体步骤,包括创建新模型、添加电源和负载、搭建主电路、加入控制模块以及完成整个电路的连接。然后阐述了如何通过对STATCOM输出电压和电流的精确调控达到无功补偿的目的,并展示了具体的仿真结果分析方法,如读取仿真数据、提取关键参数、绘制无功功率变化曲线等。最后指出,这种技术可以显著提升电力系统的稳定性与电能质量,展望了STATCOM在未来的发展潜力。 适合人群:电气工程专业学生、从事电力系统相关工作的技术人员、希望深入了解无功补偿技术的研究人员。 使用场景及目标:适用于想要掌握MATLAB/SimuLink软件操作技能的人群,特别是那些专注于电力电子领域的从业者;旨在帮助他们学会建立复杂的电力系统仿真模型,以便更好地理解STATCOM的工作机制,进而优化实际项目中的无功补偿方案。 其他说明:文中提供的实例代码可以帮助读者直观地了解如何从零开始构建一个完整的三相STATCOM仿真环境,并通过图形化的方式展示无功补偿的效果,便于进一步的学习与研究。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值