Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.io.*;
- import java.util.*;
- public class YaF {
- final static String file = "taxi";
- public static void solve(Input in, PrintWriter out) throws IOException {
- long len = in.nextLong();
- long d = in.nextLong();
- int n = in.nextInt();
- long[] xs = new long[n];
- for (int i = 0; i < n; ++i) {
- xs[i] = in.nextLong();
- }
- Arrays.sort(xs);
- int reserved = 0;
- while (reserved < n && xs[reserved] < len - d) {
- ++reserved;
- }
- if (reserved == n) {
- out.println(0);
- return;
- }
- if (xs[n - 1] >= d + len) {
- out.println(1);
- return;
- }
- long x = 0;
- int ans = 0;
- for (int i = n - 1; i >= 0; --i) {
- if (i == reserved) {
- continue;
- }
- if (xs[i] < d - x) {
- out.println(0);
- return;
- }
- ans++;
- x += xs[i] - (d - x);
- if (x >= len) {
- out.println(ans);
- return;
- }
- if (x + xs[reserved] - (d - x) >= len) {
- out.println(ans + 1);
- return;
- }
- }
- out.println(0);
- }
- public static void main(String[] args) throws IOException {
- PrintWriter out = new PrintWriter(file + ".out");
- solve(new Input(new BufferedReader(new FileReader(file + ".in"))), out);
- out.close();
- }
- static class Input {
- BufferedReader in;
- StringTokenizer st;
- public Input(BufferedReader in) {
- this.in = in;
- eat("");
- }
- public Input(String s) {
- this.in = new BufferedReader(new StringReader(s));
- }
- public void eat(String str) {
- st = new StringTokenizer(str);
- }
- public String next() throws IOException {
- while (!st.hasMoreTokens()) {
- String line = in.readLine();
- if (line == null) {
- return null;
- }
- eat(line);
- }
- return st.nextToken();
- }
- public int nextInt() throws IOException {
- return Integer.parseInt(next());
- }
- public long nextLong() throws IOException {
- return Long.parseLong(next());
- }
- public double nextDouble() throws IOException {
- return Double.parseDouble(next());
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement