이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#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... |