-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathQ.cpp
More file actions
41 lines (35 loc) 路 910 Bytes
/
Copy pathQ.cpp
File metadata and controls
41 lines (35 loc) 路 910 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
// MODIFICATION OF LCS
// (CONDITIONAL LCS)
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pl = std::pair<ll, ll>;
using vl = std::vector<long long>;
using sl = std::set<ll>;
using ml = std::map<ll, ll>;
ll mod = 1e9 + 7;
ll MAX = 1e9;
signed main() {
ll n;
cin >> n;
vl arr(n), beauty(n);
for (int i = 0; i < n; i++) cin >> arr[i];
for (int i = 0; i < n; i++) cin >> beauty[i];
vector<pl> lis;
for (int i = 0; i < n; i++)
{
pl x = make_pair(arr[i], beauty[i]);
auto it = lower_bound(lis.begin(), lis.end(), x);
if (it != lis.end())
{
if (beauty[i] >= it->second) *it = x;
// else *it = x;
}
else lis.push_back(x);
}
ll ans = 0;
cout << lis.size() << endl;
for(int i = 0; i < lis.size(); i++) ans += lis[i].second;
cout << ans << '\n';
return 0;
}