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 long double ld;
typedef pair<int, int> pii;
#define fi first
#define se second
#define mp make_pair
#define fastIO ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
const int N = 105;
const int S = N * (N + 1);
const int M = S/2;
const int inf = (int)1e9;
int a[N];
int main(){
fastIO;
int n, l, r, k;
cin >> n >> l >> r >> k;
int ans = 0;
for(int i = 1; i <= n; i ++ ){
cin >> a[i];
ans += (i >= l && i <= r) * a[i];
}
int s1 = l - 1;
int s2 = n - l + 1;
int sum;
int cost;
for(int i = 0 ; i < (1 << s2) ; i ++ ){
for(int j = 0 ; j < (1 << s1) ; j ++ ){
if(__builtin_popcount(i) != __builtin_popcount(j)) continue;
sum = 0;
cost = 0;
for(int y = 0 ; y < s2; y ++ ){
if((i & (1 << y))) cost += l + y;
else sum += a[l + y];
}
for(int y = 0 ;y < s1; y ++ ){
if((j & (1 << y))) {
sum += a[1 + y];
cost -= 1 + y;
}
}
if(cost <= k)
ans = min(ans, sum);
}
}
cout << ans << "\n";
return 0;
}
# | 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... |