# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
1158238 | sunflower | Holiday (IOI14_holiday) | C++17 | 0 ms | 0 KiB |
#ifndef SUN
#include "holiday.h"
#endif // SUN
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define MASK(x) (1LL << (x))
#define BIT(x, i) (((x) >> (i)) & 1)
#define SZ(x) ((int) (x).size())
#define ALL(a) (a).begin(), (a).end()
#define FOR(i, a, b) for (int i = (a); i <= (b); ++i)
#define FORD(i, a, b) for (int i = (a); i >= (b); --i)
#define debug(x) cerr << "[" << #x << " = " << (x) << "]" << endl
#define left __left
#define right __right
#define prev __prev
#define fi first
#define se second
template <class X, class Y>
bool maximize(X &x, Y y) {
if (x < y) return x = y, true;
else return false;
}
template <class X, class Y>
bool minimize(X &x, Y y) {
if (x > y) return x = y, true;
else return false;
}
int numPlace, start, days;
#define MAX_N 100'100
ll a[MAX_N + 2];
namespace subtask1 {
bool check() {
return (numPlace <= 20);
}
ll solve() {
ll ans = 0;
FOR(mask, 0, MASK(numPlace) - 1) {
if (BIT(mask, start) == 0) continue;
int minBit = -1, maxBit = -1; /// position;
int numBit = 0;
ll res = 0;
FOR(i, 0, numPlace - 1) {
if (BIT(mask, i)) {
++numBit;
maxBit = i;
if (minBit == -1) minBit = i;
res += a[i];
}
}
if (numBit + maxBit - minBit + min(maxBit - start, start - minBit) <= days) {
maximize(ans, res);
}
/// case2: don't visit at start;
numBit--;
res -= a[start];
if (numBit + maxBit - minBit + min(maxBit - start, start - minBit) <= days) {
maximize(ans, res);
}
}
return ans;
}
}
long long int findMaxAttraction(int __n, int __start, int __d, ll attraction[]) {
numPlace = __n;
start = __start;
days = __d;
FOR(i, 0, numPlace - 1) a[i] = attraction[i];
if (subtask1 :: check()) return subtask1 :: solve();
}
#ifdef SUN
int main() {
ios_base::sync_with_stdio(false);cin.tie(nullptr);
freopen("test.inp","r",stdin);
freopen("test.out","w",stdout);
cin >> numPlace >> start >> days;
FOR(i, 0, numPlace - 1) cin >> a[i];
cout << findMaxAttraction(numPlace, start, days, a);
return 0;
}
#endif // SUN
/* Discipline - Calm */