Submission #72522810
Source Code Expand
#include<bits/stdc++.h>
#define LL long long
#define PII pair<int, int>
#define PLL pair<LL, LL>
#define PLI pair<LL, int>
using namespace std;
inline void solve() {
int n, k; LL x; cin >> n >> k >> x;
vector<LL> a(n + 1);
for (int i = 1; i <= n; i++) cin >> a[i];
sort(a.begin() + 1, a.end());
int ans = -1; LL sum = 0;
for (int i = 1; i <= k; i++) sum += a[i];
if (sum < x) {
cout << "-1\n";
return;
}
sum = 0;
for (int i = k; i >= 1; i--) {
sum += a[i];
if (sum >= x) {
ans = k - i + 1 + n - k;
break;
}
}
cout << ans << "\n";
}
signed main() {
ios::sync_with_stdio(false), cin.tie(nullptr), cout.tie(nullptr);
int t = 1;
//cin >> t;
while (t--) solve();
return 0;
}
Submission Info
| Submission Time | |
|---|---|
| Task | C - Sake or Water |
| User | C202627yehan |
| Language | C++23 (GCC 15.2.0) |
| Score | 300 |
| Code Size | 738 Byte |
| Status | AC |
| Exec Time | 33 ms |
| Memory | 5760 KiB |
Judge Result
| Set Name | Sample | All | ||||
|---|---|---|---|---|---|---|
| Score / Max Score | 0 / 0 | 300 / 300 | ||||
| Status |
|
|
| 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 | 3540 KiB |
| example_01.txt | AC | 1 ms | 3548 KiB |
| example_02.txt | AC | 1 ms | 3452 KiB |
| hand_00.txt | AC | 16 ms | 5696 KiB |
| hand_01.txt | AC | 16 ms | 5580 KiB |
| hand_02.txt | AC | 31 ms | 5684 KiB |
| hand_03.txt | AC | 31 ms | 5704 KiB |
| hand_04.txt | AC | 31 ms | 5732 KiB |
| hand_05.txt | AC | 32 ms | 5580 KiB |
| hand_06.txt | AC | 31 ms | 5632 KiB |
| hand_07.txt | AC | 1 ms | 3564 KiB |
| hand_08.txt | AC | 1 ms | 3584 KiB |
| hand_09.txt | AC | 1 ms | 3540 KiB |
| hand_10.txt | AC | 1 ms | 3568 KiB |
| hand_11.txt | AC | 16 ms | 5668 KiB |
| random_00.txt | AC | 33 ms | 5668 KiB |
| random_01.txt | AC | 33 ms | 5760 KiB |
| random_02.txt | AC | 32 ms | 5704 KiB |
| random_03.txt | AC | 33 ms | 5640 KiB |
| random_04.txt | AC | 32 ms | 5652 KiB |
| random_05.txt | AC | 31 ms | 5696 KiB |
| random_06.txt | AC | 32 ms | 5704 KiB |
| random_07.txt | AC | 32 ms | 5640 KiB |
| random_08.txt | AC | 33 ms | 5664 KiB |
| random_09.txt | AC | 33 ms | 5704 KiB |
| random_10.txt | AC | 33 ms | 5704 KiB |
| random_11.txt | AC | 32 ms | 5684 KiB |
| random_12.txt | AC | 32 ms | 5688 KiB |
| random_13.txt | AC | 32 ms | 5612 KiB |
| random_14.txt | AC | 33 ms | 5696 KiB |
| random_15.txt | AC | 32 ms | 5580 KiB |
| random_16.txt | AC | 32 ms | 5696 KiB |
| random_17.txt | AC | 33 ms | 5704 KiB |