-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest.cpp
More file actions
68 lines (67 loc) · 1.79 KB
/
Copy pathtest.cpp
File metadata and controls
68 lines (67 loc) · 1.79 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
#include<bits/stdc++.h>
#include <cstdio>
using namespace std;
#define ll long long
#define PB push_back
#define ld long double
#define ff first
#define ss second
# define st(v) (v).begin(),(v).end()
const int dx[4] = {1,0,0,-1};
const int dy[4] = {0,-1,1,0};
const int nmax = 50 + 5 ;
vector < int > a(nmax);
int K ;
void solve( ){
int n ;
cin >> n >> K ;
for( int i = 0 ; i < n ; i++) cin >> a[i] ;
int sum1 = 0 ;
int ans = 0 ;
for( int left = 0 ; left <=n ; left++){
if(left!=0)
sum1+=a[left-1];
int sum2 = 0 ;
for( int right = n ; right >= 0 ; right--){
if(right!=n){
sum2+=a[right];
}
if(left<=right){
int remain = K - (n-right+left);
if(remain>=0){
ans = max(ans,sum1+sum2);
int sum = sum1 + sum2 ;
set < int > s ;
for( int i = 0 ; i < left ; i++){
s.insert(a[i]);
}
for( int i = n-1 ; i >=right ; i--){
s.insert(a[i]);
}
for( int x : s){
if(sum-x>=sum && remain>0){
sum-=x;
ans = max(ans,sum);
remain--;
}
else{
break ;
}
}
}
}
}
}
cout << ans ;
}
int main()
{
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
int q=1;
//cin >> q;
for( int i = 0 ; i < q ; i++){
solve();
}
}