HDU 6047 17多校 Maximum Sequence(优先队列)
Given two integer sequences {ai} and {bi} with the same length n, you are to find the next n numbers of {ai}: an+1…a2n. Just like always, there are some restrictions on an+1…a2n: for each number ai, you must choose a number bk from {bi}, and it must satisfy ai≤max{aj-j│bk≤j<i}, and any bk can’t be chosen more than once. Apparently, there are a great many possibilities, so you are required to find max{∑2nn+1ai} modulo 109+7 .
Now Steph finds it too hard to solve the problem, please help him.
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.
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;
#include<cstdio>
#include<iostream>
#include<cmath>
#include<algorithm>
#include<string.h>
#include<queue>
#include<vector>
using namespace std; #define MOD 1000000000+7 struct node
{
long long num,ip,dis;
}; long long b[]; struct cmp
{
bool operator()(node q,node p)
{
return q.dis<p.dis;
}
}; int main()
{
long long n;
while(~scanf("%lld",&n))
{
priority_queue<node,vector<node>,cmp>Q;
node a;
for(int i=;i<=n;i++)
{
scanf("%lld",&a.num);
a.ip=i;
a.dis=a.num-a.ip;
Q.push(a);
}
for(int i=;i<=n;i++)
scanf("%lld",&b[i]);
sort(b+,b++n);
long long res=;
for(int i=;i<=n;i++)
{
while(Q.top().ip<b[i])
Q.pop();
node tmp=Q.top();
res+=tmp.dis;
res%=MOD;
tmp.ip=n+i;
tmp.num=tmp.dis;
tmp.dis-=tmp.ip;
Q.push(tmp);
}
printf("%lld\n",res);
}
return ;
}
HDU 6047 17多校 Maximum Sequence(优先队列)的更多相关文章
- HDU 6140 17多校8 Hybrid Crystals(思维题)
题目传送: Hybrid Crystals Problem Description > Kyber crystals, also called the living crystal or sim ...
- HDU 6143 17多校8 Killer Names(组合数学)
题目传送:Killer Names Problem Description > Galen Marek, codenamed Starkiller, was a male Human appre ...
- HDU 3130 17多校7 Kolakoski(思维简单)
Problem Description This is Kolakosiki sequence: 1,2,2,1,1,2,1,2,2,1,2,2,1,1,2,1,1,2,2,1……. This seq ...
- HDU 6103 17多校6 Kirinriki(双指针维护)
Problem Description We define the distance of two strings A and B with same length n isdisA,B=∑i=0n− ...
- HDU 6106 17多校6 Classes(容斥简单题)
Problem Description The school set up three elective courses, assuming that these courses are A, B, ...
- HDU 6049 17多校2 Sdjpx Is Happy(思维题difficult)
Problem Description Sdjpx is a powful man,he controls a big country.There are n soldiers numbered 1~ ...
- HDU 6045 17多校2 Is Derek lying?
题目传送:http://acm.hdu.edu.cn/showproblem.php?pid=6045 Time Limit: 3000/1000 MS (Java/Others) Memory ...
- HDU 6124 17多校7 Euler theorem(简单思维题)
Problem Description HazelFan is given two positive integers a,b, and he wants to calculate amodb. Bu ...
- HDU 6038 17多校1 Function(找循环节/环)
Problem Description You are given a permutation a from 0 to n−1 and a permutation b from 0 to m−1. D ...
随机推荐
- leetcode-algorithms-36 Valid Sudoku
leetcode-algorithms-36 Valid Sudoku Determine if a 9x9 Sudoku board is valid. Only the filled cells ...
- Oracle 11.2.0.4.0 Dataguard部署和日常维护(5)-Datauard 主备切换和故障转移篇
1. dataguard主备切换 1.1. 查看当前主备库是否具备切换条件 on slave select sequence#,first_time,next_time,archived,appl ...
- Java序列化的作用和反序列化
1.序列化是干什么的? 简单说就是为了保存在内存中的各种对象的状态(也就是实例变量,不是方法),并且可以把保存的对象状态再读出来.虽然你可以用你自己的各种各样的方法来保存object states,但 ...
- ActiveMQ 消息的重新投递
正常情况下:consumer 消费完消息后,会发送"标准确认"给 broker,这个确认对象以 MessageAck 类表征: // 省略其他代码.类中定义了各种确认的类型 pub ...
- python dpkt 解析 pcap 文件
dpkt Tutorial #2: Parsing a PCAP File 原文链接:https://jon.oberheide.org/blog/2008/10/15/dpkt-tutorial-2 ...
- redis集群搭建教程(以3.2.2为例)
redis从3.0版本开始支持集群,2.X版本主支持sentinel主从模式:所以要搭建集群务必下载3.0以上版本,本教程以3.2.2版本为例. redis集群最少要有3个主节点,最典型的是3主3从组 ...
- MFC消息-自定义消息
转:http://blog.csdn.net/penpenandtongtong/article/details/18598907 像MFC的窗口发送消息,可以进行自定义的动作行为,因此很多时候非常有 ...
- Vmware tools install
Vmware tools 1◆ 下载 2◆ diagram Ifcfg-eth0 =====>关闭防火墙 systemctl stop firewalld.service ===== ...
- 回声UDP服务器端/客户端
UDP是具有数据边界的协议,传输中调用I/O函数的次数非常重要.输入函数的调用次数要和输出函数的调用次数完全一致,这样才能保证接受全部已发送的数据. TCP套接字中需注册待传输数据的目标IP和端口,而 ...
- 【基础】火狐和谷歌在Selenium3.0上的启动(二)
参考地址:http://www.cnblogs.com/fnng/p/5932224.html https://github.com/mozilla/geckodriver [火狐浏览器] 火狐浏览器 ...