제출 #1358602

#제출 시각아이디문제언어결과실행 시간메모리
1358602tamir1Candy (EGOI23_candy)C++20
22 / 100
58 ms452 KiB
#include <bits/stdc++.h>
using namespace std;

#define int long long
#define ff first
#define ss second
#define pb push_back
#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend()
#define sz(a) (int)(a).size()

const int inf = 1e18;

void solve() {
    // cout << "hello\n";
    int n, m, s;
    cin >> n >> m >> s;
    vector<int> a(n);
    for(int &i : a) cin >> i;
    int ans = inf;
    for(int i = 0; i < (1 << n); i++) {
        int cnt = 0, sum = 0, pos = 0;
        for(int j = 0; j < n; j++) {
            if(i & (1 << j)) {
                sum += a[j];
                pos += j - cnt++;
            }
        }
        if(cnt == m && sum >= s) ans = min(ans, pos);
    }
    if(ans == inf) cout << "NO\n";
    else cout << ans << '\n';
}

signed main() {
    ios_base::sync_with_stdio(0);cin.tie(0);
    int t = 1;
    // cin >> t;
    while(t--) solve();
    return 0;
}
#결과 실행 시간메모리채점기 출력
결과를 불러오는 중입니다…
#결과 실행 시간메모리채점기 출력
결과를 불러오는 중입니다…
#결과 실행 시간메모리채점기 출력
결과를 불러오는 중입니다…
#결과 실행 시간메모리채점기 출력
결과를 불러오는 중입니다…
#결과 실행 시간메모리채점기 출력
결과를 불러오는 중입니다…
#결과 실행 시간메모리채점기 출력
결과를 불러오는 중입니다…