-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathday_bitonic.cpp
More file actions
54 lines (53 loc) · 1.04 KB
/
day_bitonic.cpp
File metadata and controls
54 lines (53 loc) · 1.04 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
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const int Mod = 1e9 + 7;
int dp1[105], dp2[105], dp[105];
int main()
{
int n;
cin >> n;
int a[n + 1];
for (int i = 1; i <= n; i++)
{
cin >> a[i];
}
memset(dp1, 0, sizeof(dp1));
memset(dp2, 0, sizeof(dp2));
for (int i = 1; i <= n; i++)
{
for (int j = 0; j < i; j++)
{
if (a[j] < a[i])
{
dp1[i] = max(dp1[j] + a[i], dp1[i]);
}
}
}
for (int i = n+1; i >= 1; i--)
{
for (int j = n+1; j > i; j--)
{
if (a[j] < a[i])
{
dp2[i] = max(dp2[j] + a[i], dp2[i]);
}
}
}
for(int i = 1; i <= n; i++)
{
cout << dp1[i] << " ";
}
cout << endl;
for(int i = 1; i <= n; i++)
{
cout << dp2[i] << " ";
}
cout << endl;
int res = 0;
for (int i = 1; i <= n; i++)
{
res = max(res, dp1[i] + dp2[i] - a[i]);
}
cout << res << endl;
}