Esempio n. 1
0
  public void solve(int testNumber, InputReader in, PrintWriter out) {
    int N = in.nextInt(), K = in.nextInt(), a = in.nextInt();
    int M = in.nextInt();

    int[] A = new int[M];
    for (int i = 0; i < M; ++i) A[i] = in.nextInt();

    int cnt = (N + 1) / (a + 1);

    TreeSet<Integer> S = new TreeSet<>();
    S.add(0);
    S.add(N + 1);

    for (int i = 0; i < M; ++i) {
      int x = A[i];

      int prev = S.lower(x), next = S.higher(x);

      int ccnt = (next - prev) / (a + 1);
      int ncnt = (x - prev) / (a + 1) + (next - x) / (a + 1);

      cnt -= ccnt;
      cnt += ncnt;

      if (cnt < K) {
        out.println(i + 1);
        return;
      }

      S.add(x);
    }

    out.println(-1);
  }
  public void solve(int testNumber, InputReader in, PrintWriter out) {
    int n = in.nextInt(), m = in.nextInt(), k = in.nextInt() - 1;

    int pos = 0;
    int[] sa = new int[m + 1], sb = new int[m + 1];
    for (int i = 1; i <= m; ++i) {
      sa[i] = in.nextInt() - 1;
      sb[i] = in.nextInt() - 1;
    }

    int[] posk = new int[m + 2];
    posk[m + 1] = k;
    for (int i = m; i > 0; --i) {
      posk[i] = posk[i + 1];
      if (posk[i] == sa[i] || posk[i] == sb[i]) {
        posk[i] ^= sa[i] ^ sb[i];
      }
    }

    int pos0 = 0;
    for (int i = 1; i <= m; ++i) {
      if (pos0 == posk[i + 1]) {
        out.println(i);
        return;
      }
      if (pos0 == sa[i] || pos0 == sb[i]) {
        pos0 ^= sa[i] ^ sb[i];
      }
    }

    throw new RuntimeException();
  }