【题目链接】: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. python 字符串的处理技巧--join

    >>> '+'.join('1234')'1+2+3+4'>>> '+'.join(a for a in '1234')'1+2+3+4'>>> ...

  2. nslookup查不到数据

    ch查不到数据 换一个ip就可以了,什么原理?

  3. MVC的学习步骤

    (1)搭建环境(2)如何完成Controller和 Model的映射(3)如何把值传给Controller(4)Controller如何把值传给viewer(5)异常处理(6)页面标签(7)文件上传( ...

  4. tumblr arch information

    http://developer.51cto.com/art/201305/395757.htm 每月超过30%的增长当然不可能没有挑战,其中可靠性问题尤为艰巨.每天5亿次浏览量,峰值每秒4万次请求, ...

  5. IO流4 --- IO流体系 --- 技术搬运工(尚硅谷)

  6. 洛谷P1002 过河卒 [2017年4月计划 动态规划15]

    P1002 过河卒 题目描述 棋盘上A点有一个过河卒,需要走到目标B点.卒行走的规则:可以向下.或者向右.同时在棋盘上C点有一个对方的马,该马所在的点和所有跳跃一步可达的点称为对方马的控制点.因此称之 ...

  7. Mac上的包管理器Homebrew的介绍及安装和使用实践

    Homebrew的作用 Homebrew是OS X上强大的包管理器,为系统软件提供了非常方便的安装方式,独特式的解决了包的依赖问题,并不再需要烦人的sudo,一键式编译,无参数困扰. 如何安装Home ...

  8. Hdu 1068 最小路径覆盖

    Girls and Boys Time Limit: 20000/10000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) ...

  9. LintCode刷题笔记-- BackpackIV

    标签: 动态规划 描述: Given an integer array nums with all positive numbers and no duplicates, find the numbe ...

  10. Direct2D 第4篇 渐变画刷

    原文:Direct2D 第4篇 渐变画刷 #include <windows.h> #include <d2d1.h> #include <d2d1helper.h> ...