Submission #72557667


Source Code Expand

#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
int main() {
    long long n, k, x;
    cin >> n >> k >> x;
    vector<long long> a(n);
    for (int i = 0; i < n; i++) {
        cin >> a[i];
    }
    sort(a.begin(), a.end());
    vector<long long> prefix(n + 1, 0);
    for (int i = 0; i < n; i++) {
        prefix[i + 1] = prefix[i] + a[i];
    }
    long long r = n - k;
    long long ans = -1;
    for (long long t = 1; t <= k; t++) {
        long long m = t + r;  // 必须选的杯子数
        if (m > n) break;
        long long sum_t = prefix[n - m + t] - prefix[n - m];
        if (sum_t >= x) {
            ans = m;
            break;
        }
    }
    if (x == 0) {
        cout << 0 << endl;
    } else {
        cout << ans << endl;
    }
    return 0;
}

Submission Info

Submission Time
Task C - Sake or Water
User Dfsaot
Language C++23 (GCC 15.2.0)
Score 300
Code Size 836 Byte
Status AC
Exec Time 94 ms
Memory 8108 KiB

Judge Result

Set Name Sample All
Score / Max Score 0 / 0 300 / 300
Status
AC × 3
AC × 33
Set Name Test Cases
Sample example_00.txt, example_01.txt, example_02.txt
All example_00.txt, example_01.txt, example_02.txt, hand_00.txt, hand_01.txt, hand_02.txt, hand_03.txt, hand_04.txt, hand_05.txt, hand_06.txt, hand_07.txt, hand_08.txt, hand_09.txt, hand_10.txt, hand_11.txt, random_00.txt, random_01.txt, random_02.txt, random_03.txt, random_04.txt, random_05.txt, random_06.txt, random_07.txt, random_08.txt, random_09.txt, random_10.txt, random_11.txt, random_12.txt, random_13.txt, random_14.txt, random_15.txt, random_16.txt, random_17.txt
Case Name Status Exec Time Memory
example_00.txt AC 1 ms 3496 KiB
example_01.txt AC 1 ms 3672 KiB
example_02.txt AC 1 ms 3652 KiB
hand_00.txt AC 83 ms 8108 KiB
hand_01.txt AC 83 ms 7964 KiB
hand_02.txt AC 72 ms 8020 KiB
hand_03.txt AC 71 ms 8024 KiB
hand_04.txt AC 74 ms 8036 KiB
hand_05.txt AC 73 ms 7920 KiB
hand_06.txt AC 74 ms 8048 KiB
hand_07.txt AC 1 ms 3652 KiB
hand_08.txt AC 1 ms 3472 KiB
hand_09.txt AC 1 ms 3544 KiB
hand_10.txt AC 1 ms 3536 KiB
hand_11.txt AC 83 ms 8048 KiB
random_00.txt AC 92 ms 7964 KiB
random_01.txt AC 91 ms 8016 KiB
random_02.txt AC 93 ms 8108 KiB
random_03.txt AC 92 ms 7996 KiB
random_04.txt AC 91 ms 8016 KiB
random_05.txt AC 92 ms 8108 KiB
random_06.txt AC 93 ms 7956 KiB
random_07.txt AC 91 ms 8052 KiB
random_08.txt AC 93 ms 8044 KiB
random_09.txt AC 93 ms 7896 KiB
random_10.txt AC 92 ms 8036 KiB
random_11.txt AC 92 ms 8024 KiB
random_12.txt AC 93 ms 8108 KiB
random_13.txt AC 93 ms 8020 KiB
random_14.txt AC 94 ms 8032 KiB
random_15.txt AC 93 ms 7956 KiB
random_16.txt AC 94 ms 7996 KiB
random_17.txt AC 94 ms 8016 KiB