# HDU 6047 Maximum Sequence （贪心）

## 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.

## AC 代码

#include <cstdio>
#include <cstring>
#include <algorithm>
#include <cmath>
#include <vector>
#include<queue>
#include<iostream>
using namespace std ;

typedef __int64 LL;
typedef pair<LL,int> P;

const int mod = 1e9+7;
int main()
{
ios::sync_with_stdio(false);
int n;
while(cin>>n)
{
priority_queue<P>sk;
priority_queue<int,vector<int>,greater<int> >b;
LL ans=0;
for(int i=1; i<=n; i++)
{
LL x;
cin>>x;
sk.push(P(x-i,i));
}
for(int i=1; i<=n; i++)
{
int x;
cin>>x;
b.push(x);
}
for(int ti=n+1; !b.empty(); ti++)
{
int i=b.top();
b.pop();
while(sk.top().second<i)
sk.pop();
P p=sk.top();
sk.push(P(p.first-ti,ti));
ans=(ans+p.first)%mod;
}
cout<<ans<<endl;
}
return 0;
}