Untitled
unknown
c_cpp
a year ago
871 B
1
Indexable
#include<bits/stdc++.h> using namespace std; using l = long; l fun(vector<int> & prices, vector<int> & profits){ int n = prices.size(); l ans = 0; vector<l>maxi(n, 0); 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; }
Editor is loading...