# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
36998 | szawinis | Taxis (POI13_tak) | C++14 | 1000 ms | 5920 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;
using ll = long long;
const int N = 5e5+1;
int n;
ll m, d, x[N];
bool check(int lim_idx) {
bool ret = 0;
for (int rem = 1; rem <= lim_idx; rem++) {
ll curr = 0;
for (int i = 1; i < rem && curr < d; i++)
curr += max(x[i] - (d - curr), 0ll);
for (int i = rem + 1; i <= lim_idx && curr < d; i++)
curr += max(x[i] - (d - curr), 0ll);
ret |= curr >= d && x[rem] >= m - curr;
}
return ret;
}
int main() {
scanf("%lld %lld %d", &m, &d, &n);
for(int i = 1; i <= n; i++) scanf("%lld", x+i);
sort(x+1, x+n+1, greater<ll>());
int l = 1, r = n;
while(l < r) {
int mid = l+r >> 1;
if(check(mid)) r = mid;
else l = mid+1;
}
if(!check(l)) printf("0");
else printf("%d", l);
}
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... |