2017 Multi-University Training Contest

来源:互联网 发布:黑魂3男捏脸数据 编辑:程序博客网 时间:2024/05/21 13:55

Maximum Sequence

Time Limit: 4000/2000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 827 Accepted Submission(s): 390

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

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

#include <bits/stdc++.h>#define mm(a) memset(a,0,sizeof(a))using namespace std;const int N=250003;const int mod=(int)1e9+7;int a[N],b[N];int Max[N];bool cmp(int x,int y){    return x>y;}int main(){    int n;    while(~scanf("%d",&n)){        mm(Max);        for(int i=1;i<=n;i++){            scanf("%d",a+i);        }        for(int i=1;i<=n;i++){            scanf("%d",b+i);        }        for(int i=n;i>=1;i--){            Max[i]=max(Max[i],max(Max[i+1],a[i]-i));        }        sort(Max+1,Max+n+1,cmp);        sort(b+1,b+n+1);        int Maxs=0;        long long sum=0;        int h=n+1;        int temp;        for(int i=1;i<=n;i++){            temp=max(Maxs,Max[b[i]]);            sum+=(long long)temp;            sum%=mod;            Maxs=max(Maxs,temp-h);            h++;        }        cout<<sum<<endl;    }    return 0;}
原创粉丝点击