Untitled

mail@pastecode.io avatar
unknown
c_cpp
6 months ago
873 B
4
Indexable
Never
#include<bits/stdc++.h>
using namespace std;
using l = long;
l fun(vector<int> & prices, vector<int> & profits){
    int n = prices.size();
    l ans = -1;
    vector<l>maxi(n, -1);
    for(int i = 0; i < n; i++){
        for(int j = i+1; j < n; j++){
            if(prices[i] < prices[j])
                maxi[j] = max(maxi[j], l(profits[i] + profits[j]));
        }
    }
    for(int i = 1; i < n; i++){
        for(int j = i+1; j < n; j++){
            if(prices[i] < prices[j])
                ans = max(ans, l(maxi[i] + profits[j]));
        }
    }
    return ans;
}
int main(){
    int n;
    cin >> n;
    vector<int>prices(n, 0), profits(n, 0);
    for(int i = 0; i < n; i++){
        cin >> prices[i];
    }
    for(int i = 0; i < n; i++){
        cin >> profits[i];
    }
    cout << fun(prices, profits) << '\n';
    return 0;
}