Please sign in first.
Submission #72513310
Source Code Expand
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
int main()
{
ll n, k, x;
cin >> n >> k >> x;
vector<ll> a(n);
for(int i = 0; i < n; i++) cin >> a[i];
sort(a.begin(), a.end());
vector<ll> pre(n+1, 0);
for(int i = 0; i < n; i++) pre[i+1] = pre[i] + a[i];
if(pre[k] < x)
{
cout << -1 << endl;
return 0;
}
ll need = pre[k] - x;
auto it = upper_bound(pre.begin(), pre.begin() + k, need);
int index = distance(pre.begin(), it) - 1;
cout << n - index << endl;
return 0;
}
Submission Info
| Submission Time | |
|---|---|
| Task | C - Sake or Water |
| User | captainprice27 |
| Language | C++23 (GCC 15.2.0) |
| Score | 300 |
| Code Size | 609 Byte |
| Status | AC |
| Exec Time | 101 ms |
| Memory | 8080 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 | 3604 KiB |
| example_01.txt | AC | 1 ms | 3484 KiB |
| example_02.txt | AC | 1 ms | 3580 KiB |
| hand_00.txt | AC | 90 ms | 8040 KiB |
| hand_01.txt | AC | 90 ms | 8044 KiB |
| hand_02.txt | AC | 77 ms | 8052 KiB |
| hand_03.txt | AC | 78 ms | 8080 KiB |
| hand_04.txt | AC | 79 ms | 8080 KiB |
| hand_05.txt | AC | 79 ms | 7968 KiB |
| hand_06.txt | AC | 77 ms | 8080 KiB |
| hand_07.txt | AC | 1 ms | 3648 KiB |
| hand_08.txt | AC | 1 ms | 3620 KiB |
| hand_09.txt | AC | 1 ms | 3512 KiB |
| hand_10.txt | AC | 1 ms | 3472 KiB |
| hand_11.txt | AC | 89 ms | 8040 KiB |
| random_00.txt | AC | 99 ms | 8080 KiB |
| random_01.txt | AC | 100 ms | 8052 KiB |
| random_02.txt | AC | 98 ms | 7956 KiB |
| random_03.txt | AC | 99 ms | 8052 KiB |
| random_04.txt | AC | 99 ms | 8012 KiB |
| random_05.txt | AC | 98 ms | 7920 KiB |
| random_06.txt | AC | 98 ms | 7956 KiB |
| random_07.txt | AC | 99 ms | 8012 KiB |
| random_08.txt | AC | 100 ms | 7956 KiB |
| random_09.txt | AC | 99 ms | 7976 KiB |
| random_10.txt | AC | 99 ms | 7912 KiB |
| random_11.txt | AC | 97 ms | 8068 KiB |
| random_12.txt | AC | 99 ms | 8012 KiB |
| random_13.txt | AC | 100 ms | 8080 KiB |
| random_14.txt | AC | 101 ms | 8052 KiB |
| random_15.txt | AC | 96 ms | 7976 KiB |
| random_16.txt | AC | 100 ms | 8040 KiB |
| random_17.txt | AC | 98 ms | 8032 KiB |