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;
#define fast ios::sync_with_stdio(0);cin.tie(0);
#define s second
#define f first
typedef long long ll;
const ll MOD = 998244353;
const ll LOGN = 20;
const ll MAXN = 1e6 + 5;
vector<ll> A;
ll mn = 0;
int main() {
fast
ll N, L, R, K;
cin >> N >> L >> R >> K;
A = vector<ll>(N+1);
for (int i = 1; i <= N; i++)
cin >> A[i];
for (int i = L; i <= R; i++)
mn += A[i];
for (int msk = 0; msk < (1<<N); msk++) {
vector<int> indices, mask;
if (__builtin_popcount(msk) != R - L + 1)
continue;
for (int i = L; i <= R; i++)
indices.push_back(i);
ll sum_now = 0;
for (int i = 0; i < 13; i++) {
if (msk & (1<<i)) {
mask.push_back(i+1);
sum_now += A[i+1];
}
}
ll now = 0;
for (int i = 0; i < R - L + 1; i++)
now += abs(indices[i] - mask[i]);
if (now <= K)
mn = min(mn, sum_now);
}
cout << mn << "\n";
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |