D. Mike and distribution 构造法

798D - Mike and distribution

In the beginning, it's quite easy to notice that the condition " 2·(ap1 + ... + apk) is greater than the sum of all elements in A " is equivalent to " ap1 + ... + apk is greater than the sum of the remaining elements in A ".

Now, let's store an array of indices C with Ci = i and then sort it in decreasing order according to array A, that is we must have ACi ≥ ACi + 1.

Our answer will always have size . First suppose that N is odd. Add the first index to our set, that is make p1 = C1. Now, for the remaining elements, we will consider them consecutively in pairs. Suppose we are at the moment inspecting AC2k and AC2k + 1. If BC2k ≥ BC2k + 1 we make pk + 1 = C2k, else we make pk + 1 = C2k + 1.

Why does this subset work? Well, it satisfies the condition for B because each time for consecutive non-intersecting pairs of elements we select the bigger one, and we also add BC1 to the set, so in the end the sum of the selected elements will be bigger than the sum of the remaining ones.

It also satisfies the condition for A, because Ap1 is equal or greater than the complement element of p2 (that is — the index which we could've selected instead of p2 from the above procedure — if we selected C2k then it would be C2k + 1 and vice-versa). Similarly Ap2 is greater than the complement of p3 and so on. In the end we also add the last element from the last pair and this makes the sum of the chosen subset strictly bigger than the sum of the remaining elements.

The case when N is even can be done exactly the same as when N is odd, we just pick the last remaining index in the end.

The complexity is .

#include <cstdio>
#include <iostream>
#include <algorithm>
using namespace std;
const int N = 1e5 + 7;
int a[N], b[N], c[N], p[N/2];
bool cmp(int i, int j) {return a[i] > a[j];
}
int main()
{//ios::sync_with_stdio(0);int n;while(~scanf("%d", &n)) {for (int i = 1; i <= n; ++i) {scanf("%d", a +i);c[i] = i;}for (int i = 1; i <= n; ++i)scanf("%d", b + i);sort(c + 1, c + 1 + n, cmp);int k = n + 1 >> 1, cur = 0;p[++cur] = c[1];b[n + 1] = 0;//最边界小值 for (int i = 2; i <= n; i += 2)  //cur = k ?p[++cur] = b[c[i]] > b[c[i + 1]] ? c[i] : c[i+1];printf("%d\n%d", cur, p[1]); for (int i = 2; i <= cur; ++i)printf(" %d", p[i]);puts("");}return 0;
}

转载于:https://www.cnblogs.com/qinwenjie/p/7271339.html

CF Round410 D. Mike and distribution相关推荐

  1. Mike and distribution(思维)

    Mike has always been thinking about the harshness of social inequality. He's so obsessed with it tha ...

  2. 【CodeForces - 798D】Mike and distribution (思维构造,贪心,黑科技)

    题干: Mike has always been thinking about the harshness of social inequality. He's so obsessed with it ...

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

    Mike has always been thinking about the harshness of social inequality. He's so obsessed with it tha ...

  4. Codeforces 798D Mike and distribution (构造)

    题目链接 http://codeforces.com/contest/798/problem/D 题解 前几天的模拟赛,居然出这种智商题..被打爆了QAQ 这个的话,考虑只有一个序列怎么做,把所有的排 ...

  5. CodeForces - 798D Mike and distribution(构造+思维/玄学随机数)

    题目链接:点击查看 题目大意:给出两个长度为n的数列,现在要求选出n/2+1个位置,使得两个序列中这些位置的和分别大于各自序列之和的一半 题目分析:题意换句话说,是需要让我们从数组中选出一半,要大于另 ...

  6. Codeforces Round #410 (Div. 2) D. Mike and distribution 思维+数学

    链接: http://codeforces.com/contest/798/problem/D 题意: 给你两个长度为n的数列a和b,让你选n/2+1个下标,使得2*∑ai>suma,2*∑bi ...

  7. CF789D Mike and distribution

    题目连接 一道人类智慧题.... 这道题目可以转化为在a,b中的选出一些位置,使得这些位置处的值加起来大于没有选的位置的值 我们按照a的权值排序,选择第一个元素,其与元素两两分组,每组选择b更大的那一 ...

  8. 4.30-5.1cf补题

    //yy:拒绝转载!!! 悄悄告诉你,做题累了,去打两把斗地主就能恢复了喔~~~ //yy:可是我不会斗地主吖("'▽'") ~~~那就听两遍小苹果嘛~~~ 五一假期除了花时间建模 ...

  9. [贪心专题]CF549G,CF351E,CF226D,CF1276C,CF1148E,CF798D

    文章目录 T1:CF1276C Beautiful Rectangle title solution code T2:CF226D The table title solution code T3:C ...

最新文章

  1. atmel c keil 包_Keil C软件与AVR Atmega系列下载器使用
  2. hadoop写文件 java_写文件 - Hadoop 学习手册_教程_Java开发社区
  3. java工程师linux命令,这篇文章就够了
  4. Go语言基础:method
  5. 商用密码技术与应用创新的方向是什么?安全牛发布《商密报告》全面揭晓
  6. jwt token 过期刷新_如何在SpringBoot中集成JWT(JSON Web Token)鉴权
  7. 赛玛共享按摩椅前端蓝色UI+分销返利+去除短信注册验证
  8. java 中linux命令参数说明,java中linux命令参数说明
  9. 使用PyPDF2库对pdf文件进行指定页面删除操作
  10. centos 7.5 mysql_CentOS7.5安装MySQL8以及相关设置
  11. macbook pro 开发帮助
  12. 第70天-内网安全-域横向内网漫游 Socks 代理隧道技
  13. leetcode答案集锦
  14. java jnlp_Java Web Start实践:动态生成JNLP
  15. apache-tomcat-10.0.18配置
  16. 编程中的英语单词大全
  17. Java每次从list中拿取一百条数据
  18. pygame制作飞机大战1——规划
  19. 【20】WAV格式歌曲
  20. GIT没有关联小图标(红色、绿色图标)解决方案

热门文章

  1. LeetCode OJ - Recover Binary Search Tree
  2. 异步加载js文件并执行js方法:实现异步处理网页的复杂效果
  3. 珠宝条码打印扫描解决方案
  4. Alpine Linux详解
  5. Maven中使用本地JAR包
  6. 九九乘法表的C语言实现
  7. Java异常处理机制很有意思
  8. ASP.NET性能优化小结(ASP.NETC#)(转)
  9. JAVA方法 字符串与unicode的相互转换
  10. 虚拟化简化数据中心管理