# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
28970 | khsoo01 | Taxis (POI13_tak) | C++11 | 213 ms | 5924 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>
using namespace std;
typedef long long ll;
const ll N = 500005;
ll m, d, n, a[N];
int main()
{
scanf("%lld%lld%lld",&m,&d,&n);
for(ll i=1;i<=n;i++) {
scanf("%lld",&a[i]);
}
sort(a+1, a+1+n);
ll C = 0, V = 0, X = 0;
for(ll i=n;i>=1;i--) {
if(a[i] - abs(d-C) > 0) {
C += a[i] - abs(d-C);
V++;
}
if(C >= m) {
printf("%lld\n", V);
return 0;
}
}
C = 0; V = 0;
bool flag = false;
for(ll i=0;i<=n;i++) {
if(a[i] >= m-d) {
X = a[i]; a[i] = 0;
if(!i) V--;
flag = true; break;
}
}
if(!flag) {puts("0"); return 0;}
for(ll i=n;C<d && i>=1;i--) {
if(a[i] - abs(d-C) > 0) {
C += a[i] - abs(d-C);
V++;
}
if(C + max(0ll, X-abs(d-C)) >= m) {
printf("%lld\n", V+1);
return 0;
}
}
puts("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... |