KEYENCE Programming Contest 2021 A - Two Sequences 2(思维)

题意:

KEYENCE Programming Contest 2021 A - Two Sequences 2(思维)_第1张图片

解法:
注意到i必须满足<=j,
因此c[k]=max(c[k-1],max{a[i]}*b[k]),其中i<=k.
max{a[i]}开一个变量维护一个前缀max即可.
code:
#include 
using namespace std;
#define int long long
const int maxm=2e5+5;
int ans[maxm];
int a[maxm];
int b[maxm];
int n;
signed main(){
    ios::sync_with_stdio(0);
    cin>>n;
    for(int i=1;i<=n;i++)cin>>a[i];
    for(int i=1;i<=n;i++)cin>>b[i];
    int aa=-1;
    for(int i=1;i<=n;i++){
        aa=max(aa,a[i]);
        ans[i]=max(ans[i-1],aa*b[i]);
    }
    for(int i=1;i<=n;i++){
        cout<<ans[i]<<endl;
    }
    return 0;
}

你可能感兴趣的:(KEYENCE Programming Contest 2021 A - Two Sequences 2(思维))