Codeforces Round #410 Div2 D Mike and distribution
2017-06-01 18:06
465 查看
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 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!
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.
思路:真是一道脑洞题,想了好几天没想出来,但是看了一眼题解一下子就把弯给转过来了,就是十分好做了,首先按照a的大小进行排序,然后选择第一个a所在的标号,然后就是两个选择一个b较大的编号就能得出答案了,思路真的十分巧妙,一开始想到了对a进行排序,但是就是没有往这方面想,脑洞还是不够大啊。
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!
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.
思路:真是一道脑洞题,想了好几天没想出来,但是看了一眼题解一下子就把弯给转过来了,就是十分好做了,首先按照a的大小进行排序,然后选择第一个a所在的标号,然后就是两个选择一个b较大的编号就能得出答案了,思路真的十分巧妙,一开始想到了对a进行排序,但是就是没有往这方面想,脑洞还是不够大啊。
// // main.cpp // 补题 // // Created by 尹贯宇 on 2017/6/01. // Copyright © 2017年 尹贯宇. All rights reserved. // #include <iostream> #include <algorithm> #include <cstdio> #include <queue> #include <stack> #include <set> #include <map> #include <sstream> #include <iomanip> #include <typeinfo> #include <cstring> #include <string> #include <vector> #define MAXN 110000 #define INF 1 << 29 #define MOD 1000000007 #define PI 3.14 #define LL long long using namespace std; struct Node { LL a; LL b; int id; }; bool cmp(const Node &x1, const Node &x2) { if (x1.a == x2.a) return x1.b > x2.b; return x1.a > x2.a; } Node arr[MAXN]; int main() { int n; cin >> n; for (int i = 1; i <= n; ++i) { cin >> arr[i].a; arr[i].id = i; } for (int i = 1; i <= n; ++i) cin >> arr[i].b; sort(arr + 1, arr + 1 + n, cmp); cout << n / 2 + 1 << endl; cout << arr[1].id; for (int i = 2; i <= n; i += 2) { if (arr[i].b > arr[i + 1].b) cout << " " << arr[i].id; else cout << " " << arr[i + 1].id; } cout << endl; return 0; }
相关文章推荐
- Codeforces Round #410 (Div. 2) D. Mike and distribution(贪心)
- Codeforces Round #410 (Div. 2)B. Mike and strings(暴力)
- Mike and gcd problem Codeforces Round #410 (Div. 2)
- Codeforces Round #410 (Div. 2) Mike and gcd problem 思维
- Codeforces Round #305 (Div. 2) C. Mike and Frog +B. Mike and Fun
- Codeforces Round #305 (Div. 2) D. Mike and Feet 单调栈
- Codeforces Round #305 (Div. 1) A. Mike and Frog 暴力
- Codeforces Round #305 (Div. 2), problem: (A) Mike and Fax
- Codeforces Round #305 (Div. 2)A. Mike and Fax
- Codeforces Round #305 (Div. 2) A. Mike and Fax 暴力回文串
- Codeforces Round #305 (Div. 2)——D单调/路径压缩——Mike and Feet
- Codeforces Round #305 (Div. 2), problem: (A) Mike and Fax
- Codeforces Round #305 (Div. 2)D---Mike and Feet(单调栈)
- Codeforces Round #305 (Div. 2)B. Mike and Fun
- Codeforces Round #305 (Div. 1) B. Mike and Feet(思路)
- Codeforces Round #305 (Div. 2) C. Mike and Frog
- Codeforces Round #305 (Div. 2)--A. Mike and Fax
- Codeforces Round #361 (Div. 2) C - Mike and Chocolate Thieves
- Codeforces Round #410 (Div.2) C.Mike and gcd problem-数学
- Codeforces Round #305 (Div. 1)E. Mike and Friends 后缀数组+RMQ+线段树