제출 #844568

#제출 시각아이디문제언어결과실행 시간메모리
844568vjudge1Holding (COCI20_holding)C++17
22 / 110
2 ms348 KiB
#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 timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...