# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
260458 | tbzard | Holiday (IOI14_holiday) | C++14 | 0 ms | 0 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<int, pii> pipii;
typedef pair<pii, int> piipi;
typedef pair<pii, pii> piipii;
#define mp make_pair
#define fi first
#define se second
#define all(a) (a).begin(), (a).end()
#define sz(a) (int)(a).size()
#define eb emplace_back
ll findMaxAttraction(int n, int start, int d, int attraction[]){
long long ans = 0;
for(int i=1;i<(1<<n);i++){
vector<int> b;
int l = 1e9, r = 0;
for(int j=0;j<n;j++){
if((i>>j)&1){
b.eb(j);
l = min(l, j);
r = max(r, j);
}
}
int cost = 0;
if(l <= start && start <= r) cost = min(abs(start-l + (r-l)), abs(r-start + (r-l)));
else if(r <= start) cost = start-l;
else cost = r-start;
if(cost > d) continue;
vector<int> c;
for(int i=0;i<sz(b);i++){
int val = attraction[b[i]];
c.eb(val);
}
sort(all(c));
reverse(all(c));
ll res = 0;
int cnt = 0;
for(int i=0;i<sz(c);i++){
if(cnt < d-cost){
cnt++;
res += c[i];
}
}
ans = max(ans, res);
}
return ans;
}
int main(){
int n, start, d;
cin >> n >> start >> d;
int a[n+5];
for(int i=0;i<n;i++){
cin >> a[i];
}
printf("%lld\n", findMaxAttraction(n, start, d, a));
}