-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdaysobitonic.cpp
More file actions
43 lines (40 loc) · 771 Bytes
/
daysobitonic.cpp
File metadata and controls
43 lines (40 loc) · 771 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
42
43
//
// created by:DungTD
//
#include <bits/stdc++.h>
#define faster() ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define endl '\n'
#define base int (1e9+7)
#define ll long long
using namespace std;
void solve(){
int n; cin >> n;
vector <int> a(n);
vector <int> L(n), R(n);
for (int i=0; i<n; i++) {
cin >> a[i]; L[i] = R[i] = a[i];
}
for (int i=1; i<n; i++) {
for (int j=0; j<i; j++) {
if (a[i] > a[j]) L[i] = max(L[i], L[j] + a[i]);
}
}
for (int i=n-2; i>=0; i--) {
for (int j=n-1; j>i; j--) {
if (a[i] > a[j]) R[i] = max(R[i], R[j] + a[i]);
}
}
int res = 0;
for (int i=0; i<n; i++) {
res = max(res, R[i]+L[i]-a[i]);
}
cout << res << endl;
}
int main(){
faster();
int t;
cin >> t;
while (t--)
solve();
return 0;
}