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 ...
随机推荐
- CSU OJ 1340 A Sample Problem
Description My girlfriend loves 7 very much, she thinks it is lucky! If an integer contains one or m ...
- Redis(window版本)安装及使用
1.打开redis官网http://redis.io/点击Download 2.往下拉,找到Windows,由图片中的文字可以看出Redis项目不正式支持Windows. 但是,Microsoft开放 ...
- ASP.NET Core WebAPI 开发-新建WebAPI项目 转
转 http://www.cnblogs.com/linezero/p/5497472.html ASP.NET Core WebAPI 开发-新建WebAPI项目 ASP.NET Core We ...
- PHP手册-函数参考-加密扩展
一.Crack.CSPRNG.Hash.Mcrypt.Mhash.OpenSSL.密码散列算法的对比 Crack CSPRNG Hash Mcrypt Mhash OpenSSL 密码散列算法 简 ...
- 从线程模型的角度看Netty的高性能
转载:Netty(二) 从线程模型的角度看 Netty 为什么是高性能的? 传统 IO 在 Netty 以及 NIO 出现之前,我们写 IO 应用其实用的都是用 java.io.* 下所提供的包. 比 ...
- java多线程读一个变量需要加锁吗?
如果只是读操作,没有写操作,则可以不用加锁,此种情形下,建议变量加上final关键字: 如果有写操作,但是变量的写操作跟当前的值无关联,且与其他的变量也无关联,则可考虑变量加上volatile关键字, ...
- 将16进制unsigned char数组转换成整数
/** * 将unsigned char数组转换成long long数值 * {0x00 0x00 0x20 0x00}转换之后得到8192 * * @param str 数组 * @param le ...
- node代理服务器
var express = require('express');var request = require('request');var app = express();var _URL = 'ht ...
- day4-python基础-运算符
本章节主要说明Python的运算符.举个简单的例子 4 +5 = 9 . 例子中,4 和 5 被称为操作数,"+" 称为运算符. Python语言支持以下类型的运算符: 算术运算符 ...
- alpine linux docker 安装 lxml出错的解决办法。
我习惯在docker当中用alpine来部署服务. 最近在部署flask时使用了 tiangolo/uwsgi-nginx-flask:python3.6-alpine3.7 这个镜像 别人写好的fl ...