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>
using namespace std;
#define _ int v, int tl, int tr, int l, int r, int h
#define tm (tl+tr >> 1)
#define sol v+v,tl,tm,l,r,h
#define sag v+v+1,tm+1,tr,l,r,h
#define mp make_pair
#define pb push_back
#define st first
#define nd second
typedef long long ll;
typedef pair < int , int > pp;
const int mod = 1e9 + 7;
const int N = 5e5 + 5;
ll A[N],m,d,n,i,j,x;
void fail() { cout << 0; exit(0); }
int main(){
cin >> m >> d >> n;
for(i=1;i<=n;i++) scanf("%lld", &A[i]);
sort(A+1 , A+n+1);
reverse(A+1 , A+n+1);
if(A[1] < m-d) fail();
for(i=1;i<=n && A[i] >= m-d;i++){
if(A[i] < d-x) fail();
x += A[i] - max(0LL , d - x);
if(x >= m) { cout << i; return 0; }
}
fail();
i--;
x = 0;
for(j=1;j<i;j++){
x += A[j] - max(0LL , d - x);
}
for(j=i+1;j<=n;j++){
x += A[j] - max(0LL , d - x);
if(x < 0) break;
if(x >= m-A[i]) { cout << j; return 0; }
}
cout << 0;
return 0;
}
Compilation message (stderr)
tak.cpp: In function 'int main()':
tak.cpp:27:40: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
for(i=1;i<=n;i++) scanf("%lld", &A[i]);
^
# | 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... |