您的位置:首页 > 大数据 > 人工智能

2017 Multi-University Training Contest - Team 2 && HDU6047

2017-07-28 11:20 411 查看
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
,b
;
int Max
;
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;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: 
相关文章推荐