# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
82648 | farukkastamonuda | Taxis (POI13_tak) | C++14 | 197 ms | 7000 KiB |
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 fi first
#define se second
#define lo long long
#define inf 1000000009
#define md 1000000007
#define li 500005
#define mp make_pair
#define pb push_back
using namespace std;
int n,tut=1,kullan[li];
lo int m,d,A[li],sum;
void fail(){
printf("0\n");
exit(0);
}
int main(){
scanf("%lld %lld %d",&m,&d,&n);
sum=d;
for(int i=1;i<=n;i++) scanf("%lld",&A[i]);
sum=d;
sort(A+1,A+n+1,greater<lo int>());
if(A[1]<m-d) fail();
for(int i=2;i<=n;i++){
if(A[i]>=m-d){
tut=i;
}
else break;
}
for(int i=1;i<=tut-1;i++) kullan[i]=1;
for(int i=1;i<=n;i++){
if(i==tut) continue;
if(kullan[i]==1){
if(A[i]<=sum) fail();
A[i]-=sum;
sum-=A[i];
if(sum<=0){
printf("%d\n",i+1);
return 0;
}
}
else{
if(A[i]<=sum){
if(A[tut]<=sum) fail();
A[tut]-=sum;
lo int gg=sum;
if(A[tut]>=gg+m-d){
printf("%d\n",i-1);
return 0;
}
fail();
}
A[i]-=sum;
sum-=A[i];
if(sum<=0){
printf("%d\n",i);
return 0;
}
}
}
A[tut]-=sum;
lo int gg=sum;
sum-=A[tut];
if(sum>0) fail();
if(A[tut]>=m-d+gg){
printf("%d\n",n);
return 0;
}
fail();
return 0;
}
Compilation message (stderr)
# | 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... |