This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
#define ll long long
#define ull unsigned long long
#define lsb(x) (x & (-x))
using namespace std;
const ll INF = 2e18;
int main() {
//ifstream cin("A.in");
//ofstream cout("A.out");
int n, i;
ll m, d;
ios::sync_with_stdio(false);
cin.tie(0), cout.tie(0);
cin >> m >> d >> n;
vector <ll> arr(n);
for(i = 0; i < n; i++) {
cin >> arr[i];
}
sort(arr.begin(), arr.end(), greater<ll>());
ll mn = INF, id = -1;
for(i = 0; i < n; i++) {
if(mn > arr[i] && arr[i] >= m - d) {
mn = arr[i];
id = i;
}
}
if(id == -1) {
cout << 0;
return 0;
}
int ans = 0;
ll x = 0;
for(i = 0; i < n && x < d; i++) {
if(id == i) {
continue;
}
if(arr[i] < d - x) {
cout << 0;
return 0;
}
x += arr[i] - (d - x);
ans++;
}
if(x < m) {
ans++;
}
cout << ans;
return 0;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |