```c
#include <iostream>
#include <cstring>
#include <string>
#include <algorithm>
#include <cstdio>
#include <cstdlib>
#include <stack>
#include <queue>
using namespace std;
const int MAXN=100005;
int n,s[MAXN],a[MAXN];
struct tree
{
int left,right;
int maxa,pos;
}t[MAXN];
tree query(int id,int l,int r)
{
if(t[id].left==l&&t[id].right==r)
return t[id];
if(t[id<<1].right>=r)
return query(id<<1,l,r);
else if(t[id<<1|1].left<=l)
return query(id<<1|1,l,r);
else
{
tree lson=query(id<<1,l,t[id<<1].right);
tree lson=query(id<<1|1,l,t[id<<1|1].left,r);
if(lson.maxa>=rson.maxa)
return lson;
return rson;
}
}
int main()
{
int i,j;
cin>>n;
for(i=0; i<n; i++)
{
cin>>t[i].s;
}
for(i=0; i<n; i++)
{
cin>>t[i].a;
}
int pos=0;
for(i=0; i<n; i++)
{
if(pos<=0)
{
tree tmp=query(1,pos+1,n);
int rpos=tmp.pos;
for(j=pos+1; j<pos; j++)
{
q.push(a[j]);
}
pos=rpos;
maxa=tmp.maxa;
}
else if(pos>=n)
{
maxa=q.top();
q.pop();
}
else
{
lmax=q.top();
tree tmp=query(1,pos+1,n);
rmax=tmp.maxa-2*s[pos];
if(lmax<rmax)
{
//怎么写???
}
}
ans[i]=ans[i-1]+maxa;
}
return 0;
}
```
by drzo @ 2018-06-02 19:46:34