Maximum Sequence

Time Limit: 4000/2000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 2404    Accepted Submission(s): 1131

Problem Description
Steph is extremely obsessed with “sequence problems” that are usually seen on magazines: Given the sequence 11, 23, 30, 35, what is the next number? Steph always finds them too easy for such a genius like himself until one day Klay comes up with a problem and ask him about it.

Given two integer sequences {ai} and {bi} with the same length n, you are to find the next n numbers of {ai}: $a_{n+1}…a_{2n}$. Just like always, there are some restrictions on $a_{n+1}…a_{2n}$: for each number $a_i$, you must choose a number $b_k$ from {bi}, and it must satisfy $a_i$≤max{$a_j$-j│$b_k$≤j<i}, and any $b_k$ can’t be chosen more than once. Apparently, there are a great many possibilities, so you are required to find max{$\sum_{n+1}^{2n}a_i$} modulo $10^9$+7 .

Now Steph finds it too hard to solve the problem, please help him.

Input
The input contains no more than 20 test cases.
For each test case, the first line consists of one integer n. The next line consists of n integers representing {ai}. And the third line consists of n integers representing {bi}.
1≤n≤250000, n≤a_i≤1500000, 1≤b_i≤n.
Output
For each test case, print the answer on one line: max{$\sum_{n+1}^{2n}a_i$} modulo $10^9$+7。
Sample Input
4 8 11 8 5 3 1 4 2
Sample Output
27

Hint

For the first sample: 1. Choose 2 from {bi}, then a_2…a_4 are available for a_5, and you can let a_5=a_2-2=9; 2. Choose 1 from {bi}, then a_1…a_5 are available for a_6, and you can let a_6=a_2-2=9;

Source
2017 Multi-University Training Contest - Team 2

题意:构造an+1到a2*n的数。构造方法是从bi中选一个数使得ai≤max{aj-j│bk≤j<i}。bi只能被选一次。求构造出来的an+1到a2*n的最大值。

思路:
aj-j中的aj是从原来a1到an中来的,而j的值是一直变大的。所以应该把大的值先加入ai+n中。
所以可以先将bi从小到大排序。用一个优先队列,存放ai-i的值,以它的较大值为优先级较高的。在构造出一个ai+n的时候并把ai+n-(i+n)放入队列中。继续往后构造,这样就能使得和最大。

#include <iostream>
#include <cstdio>
#include <cstring>
#include <queue>
#include <algorithm>
using namespace std;
const int maxn=500010;
const int mod=1e9+7;
struct node
{int i,w;friend bool operator<(node a,node b){return a.w<b.w;}
}q[maxn];
int b[maxn];
int main()
{int n;while(~scanf("%d",&n)){priority_queue<node> que;for(int i=1;i<=n;i++){scanf("%d",&q[i].w);q[i].w=q[i].w-i;q[i].i=i;que.push(q[i]);}for(int i=1;i<=n;i++)scanf("%d",&b[i]);sort(b+1,b+1+n);long long sum=0;for(int i=1;i<=n;i++){while(que.top().i<b[i]) que.pop();node tmp=que.top();sum=(sum+tmp.w)%mod;tmp.i=i+n,tmp.w=tmp.w-tmp.i;que.push(tmp);}printf("%lld\n",sum);}return 0;
}

2017 多校训练第二场 HDU 6047 Maximum Sequence(贪心+优先队列)相关推荐

  1. (2017多校训练第一场)HDU - 6034 Balala Power! 贪心

    很容易就想到把每个字母的权重都算出来,然后把权重最大的赋值成25,次大的赋值成24......以此类推. 但是字符串长度最大为100000,也就是说一个字母的权重最大是26^100000次方左右,太大 ...

  2. 2017多校第4场 HDU 6078 Wavel Sequence DP

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=6078 题意:求两个序列的公共波形子序列的个数. 解法: 类似于最长公共上升子序列,对于每个i,只考虑存 ...

  3. Swaps and Inversions hdu多校训练第二场 树状数组求逆序数+离散化

    http://acm.hdu.edu.cn/showproblem.php?pid=6318 交换相邻的元素,有几个逆序对,就交换几次使其变成顺序对 #include<bits/stdc++.h ...

  4. 2017多校第3场 HDU 6058 Kanade's sum 双链表,思维

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=6058 题外话:这场多校,真心感觉自己的无力,全队都发挥的很差,结束的时候排名掉到了90多,后期没做出字 ...

  5. 2017多校第9场 HDU 6169 Senior PanⅡ 数论,DP,爆搜

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=6169 题意:给了区间L,R,求[L,R]区间所有满足其最小质数因子为k的数的和. 解法: 我参考的这篇 ...

  6. HDU 6047 Maximum Sequence 思维

    题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=6047 题目描述: 有数组a, b长度都为n ......解释起来好麻烦, 自己看题吧 解题思路: 由 ...

  7. HDU 6047 Maximum Sequence

    Maximum Sequence Time Limit: 4000/2000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) To ...

  8. 2017 杭电多校联赛第二场 1003 Maximum Sequence(单调队列)HDU 6047

    Maximum Sequence Time Limit: 4000/2000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) ...

  9. (2017多校训练第四场)HDU - 6078 Wavel Sequence dp

    传送门:点击打开链接 定义状态dp[i][j][0]表示以a[i],b[j]结尾的且为波谷的情况总和,dp[i][j][1] 为波峰. 对于某个i,j满足a[i] == b[j],则dp[i][j][ ...

最新文章

  1. 干货分享:自动驾驶核心技术进展之车用毫米波雷达
  2. 优秀的博客与文章总结链接地址
  3. [转载].Freescale.伦德全 - 电路板级的电磁兼容设计
  4. 2018-12-25 数据库插入数据
  5. win7系统自带截图工具快捷键是什么?怎么设置快捷键
  6. Android 语音播报,语音识别demo
  7. List与Set接口的方法
  8. navicat怎么查看数据库的url_连接数据库url怎么写
  9. 这10个功能模块,手把手教你从零设计电商系统
  10. java 快速删除文件夹_如何用Java删除文件夹里的所有文件?
  11. virtualbox虚拟机上安装centOS的网络配置(安装centos时选择桥接网络)
  12. 安装node.jsvue3.0脚手架
  13. linux查文件被哪些程序占用—fuser和lsof的使用
  14. 限制用户不能删除SharePoint列表中的条目(项目)
  15. ubuntu 20.04安装输入法,微信,QQ,亲测使用很方便。
  16. 三十四、Expandable grid 可扩展的表格
  17. win10安装k8s
  18. 企业建站使用哪些主流的CMS系统?
  19. 致 Embarcadero 客户及经销伙伴信函
  20. 在Ubuntu上安装和使用miniconda

热门文章

  1. C++ Type Trait
  2. 安装Linux时报错This kernel requires an X86-64 CPU
  3. 编程求圆的面积和周长(c语言)
  4. 前端利器——炫酷的CodePen
  5. 软件管理餐饮管理系统黑盒测试,餐饮系统软件测试.docx
  6. mysql慢查询优化_常见mysql的慢查询优化方式
  7. 淘宝官方商品、交易、订单、物流接口列表(淘宝api)
  8. 快速生成APP的平台
  9. 兔死狗烹,Twitter对开发者犯下的十宗罪
  10. matlab的折线图导出矢到cad,matlab2015画出图形导出CAD脚本在哪