【题目链接】:http://codeforces.com/contest/798/problem/D

【题意】



让你选一个下标集合

p1,p2,p3..pk

使得2*(a[p1]+a[p2]+..+a[pk])>∑ai

同时2*(b[p1]+b[p2]+..+b[pk])>∑bi

【题解】



两个式子都可以转化为

a[p1]+a[p2]+..+a[pk]>剩余的元素

(移项就能得到)

接着用构造的方法搞;

首先把A数组降序排;

(排的时候要记录每个元素它原来的下标)

即a[i].val和a[i].id

然后把a[1].id加入答案;

对于剩下的n-1个

顺序成对地处理



对于a[i]和a[i+1]

看看b[a[i].id]和b[a[i+1].id]哪一个大;

哪一个大

就把相应的id加入到答案序列中;

因为a是降序排的;

且已经把一个最大的a放在了头位置;

这就能保证对于每一个ai都有一个比他小的ai;

而我们每次成对地把b大的加入答案;

也能保证每一个bi都有一个比他小的bi;

很棒的思路吧



【Number Of WA】



0



【完整代码】

#include <bits/stdc++.h>
using namespace std;
#define lson l,m,rt<<1
#define rson m+1,r,rt<<1|1
#define LL long long
#define rep1(i,a,b) for (int i = a;i <= b;i++)
#define rep2(i,a,b) for (int i = a;i >= b;i--)
#define mp make_pair
#define pb push_back
#define fi first
#define se second
#define ms(x,y) memset(x,y,sizeof x) typedef pair<int,int> pii;
typedef pair<LL,LL> pll; const int dx[9] = {0,1,-1,0,0,-1,-1,1,1};
const int dy[9] = {0,0,0,-1,1,-1,1,-1,1};
const double pi = acos(-1.0);
const int N = 1e5+100; struct abc
{
int val,id;
}; int n,b[N];
abc a[N];
vector <int> ans; bool cmp1(abc a,abc b)
{
return a.val > b.val;
} int main()
{
//freopen("F:\\rush.txt","r",stdin);
ios::sync_with_stdio(false),cin.tie(0);//scanf,puts,printf not use
cin >> n;
rep1(i,1,n)
cin >> a[i].val,a[i].id = i;
rep1(i,1,n)
cin >> b[i];
sort(a+1,a+1+n,cmp1);
ans.pb(a[1].id);
for (int i = 2;i <= n;i+=2)
{
int po = a[i].id;
if (i+1<=n && b[a[i+1].id]>b[po])
po = a[i+1].id;
ans.pb(po);
}
int len = ans.size();
cout << len << endl;
rep1(i,0,len-1)
cout << ans[i] <<' ';
return 0;
}

【codeforces 798D】Mike and distribution的更多相关文章

  1. 【codeforces 798A】Mike and palindrome

    [题目链接]:http://codeforces.com/contest/798/problem/A [题意] 让你严格改变一个字符,使得改变后的字符串为一个回文串; 让你输出可不可能; [题解] 直 ...

  2. 【codeforces 798B】Mike and strings

    [题目链接]:http://codeforces.com/contest/798/problem/B [题意] 给你n个字符串; 每次操作,你可以把字符串的每个元素整体左移(最左边那个字符跑到最后面去 ...

  3. 【codeforces 798C】Mike and gcd problem

    [题目链接]:http://codeforces.com/contest/798/problem/C [题意] 给你n个数字; 要求你进行若干次操作; 每次操作对第i和第i+1个位置的数字进行; 将 ...

  4. 【codeforces 415D】Mashmokh and ACM(普通dp)

    [codeforces 415D]Mashmokh and ACM 题意:美丽数列定义:对于数列中的每一个i都满足:arr[i+1]%arr[i]==0 输入n,k(1<=n,k<=200 ...

  5. 【codeforces 727D】T-shirts Distribution

    [题目链接]:http://codeforces.com/problemset/problem/727/D [题意] 给你6种尺寸的衣服; 他们的尺码依次为S, M, L, XL, XXL, XXXL ...

  6. 【23.33%】【codeforces 557B】Pasha and Tea

    time limit per test1 second memory limit per test256 megabytes inputstandard input outputstandard ou ...

  7. 【codeforces 707E】Garlands

    [题目链接]:http://codeforces.com/contest/707/problem/E [题意] 给你一个n*m的方阵; 里面有k个联通块; 这k个联通块,每个连通块里面都是灯; 给你q ...

  8. 【codeforces 707C】Pythagorean Triples

    [题目链接]:http://codeforces.com/contest/707/problem/C [题意] 给你一个数字n; 问你这个数字是不是某个三角形的一条边; 如果是让你输出另外两条边的大小 ...

  9. 【codeforces 709D】Recover the String

    [题目链接]:http://codeforces.com/problemset/problem/709/D [题意] 给你一个序列; 给出01子列和10子列和00子列以及11子列的个数; 然后让你输出 ...

随机推荐

  1. Linux下根目录root扩容

    参考博客:https://blog.csdn.net/qq_36527339/article/details/81772996 1.首先虚拟机关机 —> 选中要扩容的虚拟机 —>编辑虚拟机 ...

  2. Docker搭建ELK的javaweb应用日志收集存储分析系统

    1.启动elasticsearch docker run -d --name myes -p 9200:9200 elasticsearch:2.3 2.启动kibana docker run --n ...

  3. php数字转人民币金额大写

    numToRmb.php <?php header("content-type:text/html;charset=utf-8"); function numToRmb($n ...

  4. 2018-8-10-如何移动-nuget-缓存文件夹

    title author date CreateTime categories 如何移动 nuget 缓存文件夹 lindexi 2018-08-10 19:16:51 +0800 2018-2-13 ...

  5. IntelliJ IDEA中设置同时打开多个文件且分行显示

    [转载]原文链接:https://blog.csdn.net/lwl20140904/article/details/73275897 有时候要是打开多个文件,要么都显示在一行,要么因为空间不足,就给 ...

  6. 模拟20 题解(waiting)

    留坑待填 T2 #include<cstdio> #include<vector> #include<cstring> #include<iostream&g ...

  7. Qt5.9.1_MSVC2017版本调试环境安装

    参照如下链接https://blog.csdn.net/nupt_zhangtao/article/details/77444132

  8. angular依赖注入(3) —— 的提供商

    一.注册商必须写在NgModel当中,不然只能对当前组件注入 二.写法: 1.令牌:providers:[Logger,Data] 2.供应商定义对象:providers:[{provide:Logg ...

  9. ASP.NET自定义控件组件开发 第一章 第一章:从一个简单的控件谈起

    第一章:从一个简单的控件谈起 系列文章链接: ASP.NET自定义控件组件开发 第一章 待续 ASP.NET自定义控件组件开发 第一章 第二篇 接着待续 ASP.NET自定义控件组件开发 第一章 第三 ...

  10. jeecg Access restriction 问题解决

    最近导入新项目,导入所有用到的jar包,发现其中一个引用报错 import com.sun.istack.internal.Nullable; 具体信息如下: Access restriction: ...