# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
1042422 | kimnhatdev1106 | Holiday (IOI14_holiday) | C++17 | 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>
#define int long long
using namespace std;
const int N = 1e5 + 5;
int n, s, d, a[N], ans, mp[N];
void ql(int pos, int sum, int d){
if(d == 0){
ans = max(ans, sum);
return;
}
if(mp[pos] == 0){
mp[pos] = 1;
ql(pos, sum + a[pos], d - 1);
mp[pos] = 0;
}
if(pos > 0){
ql(pos - 1, sum, d - 1);
}
if(pos + 1 < n){
ql(pos + 1, sum, d - 1);
}
}
signed main(){
ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
//freopen("STOUR.inp", "r", stdin);
// freopen("STOUR.out", "w", stdout);
cin >> n >> s >> d;
for(int i = 0; i < n; i++){
cin >> a[i];
}
ql(s, 0, d);
cout << ans;
}