-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path1195C.cpp
More file actions
73 lines (72 loc) · 1.64 KB
/
1195C.cpp
File metadata and controls
73 lines (72 loc) · 1.64 KB
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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
// हर हर महादेव
#define F first
#define S second
#define dbl double
using namespace std;
#define pb push_back
#define vin(name, size) \
for (i = 0; i < size; i++) \
cin >> name[i]
#define vout(name) \
for (i = 0; i < name.size(); i++) \
cout << name[i] << " "; \
cout << endl
#include <bits/stdc++.h>
#define ll long long int
#define all(x) x.begin(), x.end()
#define Pi 3.1415926535897932384626
#define part(x, a, b) x.begin() + a, x.begin() + b
#define deb(v) cout << #v << " " << v << "\n"
#define deb2(v, k) cout << #v << " " << v << "\n" \
<< #k << " " << k << "\n"
ll dp[100002][4];
vector<ll> v, v1;
ll f(ll n, ll c)
{
// Base
if (n == -1)
return 0;
if (dp[n][c] != -1)
return dp[n][c];
// Recursive
if (c == 1)
return dp[n][c] = max(v1[n] + f(n - 1, 2), f(n - 1, 0));
else if (c == 2)
return dp[n][c] = max(v[n] + f(n - 1, 1), f(n - 1, 0));
else
return dp[n][c] = max(max(v1[n] + f(n - 1, 2), v[n] + f(n - 1, 1)), f(n - 1, 0));
}
void HHM()
{
memset(dp, -1, sizeof(dp));
ll i, j, k;
ll n;
cin >> n;
for (i = 0; i < n; i++)
{
ll d;
cin >> d;
v.pb(d);
}
for (i = 0; i < n; i++)
{
ll d;
cin >> d;
v1.pb(d);
}
cout << f(n - 1, 0);
return;
}
int main()
{
ios_base::sync_with_stdio(0), cin.tie(0);
ll t = 1;
// cin >> t;
for (ll i = 1; i <= t; i++)
{
// cout << "Case #" <<i<< ": ";
HHM();
}
}
// freopen("input.txt", "r", stdin);
// freopen("output.txt", "w", stdout);