Codeforces-798D. Mike and distribution
来源:互联网 发布:小恶魔提利昂知乎 编辑:程序博客网 时间:2024/06/10 15:11
D. Mike and distributiontime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputMike 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 n each 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. Sequence P 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!InputThe 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.OutputOn 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.Exampleinput58 7 4 8 34 2 5 3 7output31 4 5
脑洞略大
因为
问题转化为:n个数选择
按a[i]从大到小排序,得到下标集合idx[n]
当
选择idx[1] (此时a[idx[1]]是a中最大的)
然后以2个数为一组
选择
依次选择
假如选择了
所以对数组
而数组
选择
#include<stdio.h>#include <iostream>#include<stdlib.h>#include<algorithm>#include<vector>#include<deque>#include<map>#include<set>#include<queue>#include<math.h>#include<string.h>#include<string>using namespace std;#define ll long long#define pii pair<int,int>const int inf = 1e9 + 7;const int N = 1e5+5;int a[N];int idx[N];int b[N];bool cmpIdx(int x,int y){ return a[x]>a[y];}void slove(int n){ for(int i=1;i<=n;++i){ idx[i]=i; } sort(idx+1,idx+n+1,cmpIdx); printf("%d\n%d",n/2+1,idx[1]); for(int i=2;i+1<=n;i+=2){ int x=idx[i],y=idx[i+1]; int ansIdx=b[x]>b[y]?x:y; printf(" %d",ansIdx); } if(n%2==0){ printf(" %d",idx[n]); } putchar('\n');}int main(){ //freopen("/home/lu/Documents/r.txt","r",stdin); //freopen("/home/lu/Documents/w.txt","w",stdout); int n; while(~scanf("%d",&n)){ for(int i=1;i<=n;++i){ scanf("%d",a+i); } for(int i=1;i<=n;++i){ scanf("%d",b+i); } slove(n); } return 0;}
0 0
- Codeforces 798D Mike and distribution 构造
- codeforces 798D Mike and distribution
- codeforces 798D Mike and distribution
- CodeForces 798D Mike and distribution
- Codeforces-798D. Mike and distribution
- 798D Mike and distribution
- Codeforces 798D Mike and distribution(二维贪心)
- Codeforces-798D-Mike and distribution(贪心)
- codeforces 798 D. Mike and distribution 二维贪心
- Codeforces 798D Mike and distribution (构造 + 脑洞 推荐)
- CodeForces 798D Mike and distribution(二维贪心 + 思维)
- D. Mike and distribution
- CF-Codeforces Round #410 (Div. 2)-D-Mike and distribution
- Codeforces Round #410 (Div. 2) D. Mike and distribution 思维
- Codeforces Round #410 (Div. 2) D. Mike and distribution(贪心)
- Codeforces Round #410 Div2 D Mike and distribution
- Codeforces 798D Mike and distribution【思维+贪心】好题!好题!感觉智商受到了一万点伤害= =
- Codeforces798D Mike and distribution
- Linux下创建线程池
- Maven
- POJ 1079 Ratio 笔记
- JavaScript编程中的对象概念
- 5 个免费的受欢迎的 SQLite 管理工具【申明:来源于网络】
- Codeforces-798D. Mike and distribution
- [java]求数组中第2大的数
- Oracle面试题 表连接 高级排序函数
- 2、TFTP服务(宿主机环境搭建)
- C++程序设计(第三版)谭浩强 一章习题
- 手把手原生js简单轮播图
- 卷积神经网络入门
- 求助,这道题还是断错误
- 一起艳恶学习tomcat7与redis实现session共享