hdu 6047 (贪心)

来源:互联网 发布:篮球数据英文缩写psa 编辑:程序博客网 时间:2024/06/03 09:22

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}: an+1…a2nan+1…a2n. Just like always, there are some restrictions on an+1…a2nan+1…a2n: for each number aiai, you must choose a number bkbk from {bi}, and it must satisfy aiai≤max{ajaj-j│bk bk ≤ j < i}, and any bkbk can’t be chosen more than once. Apparently, there are a great many possibilities, so you are required to find max{∑2nn+1ai∑n+12nai} modulo 109109+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{ ∑2nn+1ai ∑n+12nai} modulo 109109+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;

给两个长度为n的序列a, b,现要求max(sum(a[n + 1] + … + a[2n])),其中a[i] = max(a[b[k]] … a[i - 1]),其中b[k]为b[1 … n]中的一个,每个a[i]选择的b[k]不能重复

因为b是1到n 那么保存每一个点后面所有的值中最大的即可,另外保存一个a[n+1] 代表的是后面所有的值中的最大值。而且每次与 a[n+i]和 a[b[i]] 比较最大的,并且更新

#include <bits/stdc++.h>using namespace std;const int N = 3e5+100;const int mod = 1e9+7;typedef long long ll;int a[N];int b[N];int main(){    int n;    while(scanf("%d",&n)!=EOF)    {        for(int i=1;i<=n;i++)            scanf("%d",&a[i]);        for(int i=1;i<=n;i++)            scanf("%d",&b[i]);        ll total=0;        int maxx=a[n]-n;        for(int i=n;i>0;i--)        {            maxx=max(maxx,a[i]-i);            a[i]=maxx;        }        sort(b+1,b+n+1);        total+=a[b[1]];        a[n+1]=a[b[1]]-n-1;        for(int i=2;i<=n;i++)        {            int h=b[i];            int res=max(a[b[i]],a[n+1]);            total+=res;            total%=mod;            a[n+1]=max(a[n+1],res-n-i);        }        printf("%lld\n",total%mod );    }}
原创粉丝点击
热门问题 老师的惩罚 人脸识别 我在镇武司摸鱼那些年 重生之率土为王 我在大康的咸鱼生活 盘龙之生命进化 天生仙种 凡人之先天五行 春回大明朝 姑娘不必设防,我是瞎子 手机信号被屏蔽了怎么办 西安市旅游年卡怎么办 广电宽带网速慢怎么办 电视智能卡坏了怎么办 家乐卡二次授信怎么办? 邢台银行倒闭了怎么办 不敢和导师交流怎么办 考上一个破大学怎么办 腻子粉检测报告怎么办 电子厂插件很慢怎么办 预付费电表跳闸怎么办 电费有疑问怎么办大连 农村电表箱坏了怎么办 农村电表没电怎么办 家里电费特别高怎么办 电表读卡失败怎么办 电表卡消磁了怎么办 智能表采集失败怎么办 电脑没有蓝牙功能怎么办 判决后无力偿还怎么办 dz47-63c63跳闸怎么办 租房合同丢了怎么办 北京土地承包合同丢失怎么办 租赁合同丢失了怎么办 房屋租赁合同丢失怎么办 学校没发学生证怎么办 学校银行卡丢了怎么办 报税名字忘了怎么办 地税零申报漏报怎么办 欠中联重科施工电梯钱怎么办 大型船舶起锚正横后怎么办 老师不会教孩子怎么办 个体工商营业证怎么办 广州市住房公积怎么办 苹果账号禁用了怎么办 换单位后公积金怎么办 青岛不发工资怎么办 上北影不会唱歌怎么办 黑驾校不退钱怎么办 驾驶证被扣半年怎么办 买个二手车落户怎么办