結果

問題 No.489 株に挑戦
ユーザー takeya_okinotakeya_okino
提出日時 2019-07-06 15:14:23
言語 Java21
(openjdk 21)
結果
WA  
実行時間 -
コード長 1,963 bytes
コンパイル時間 4,122 ms
コンパイル使用メモリ 79,208 KB
実行使用メモリ 78,596 KB
最終ジャッジ日時 2023-10-26 00:01:42
合計ジャッジ時間 19,223 ms
ジャッジサーバーID
(参考情報)
judge11 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 WA -
testcase_01 WA -
testcase_02 AC 146 ms
58,420 KB
testcase_03 AC 146 ms
58,408 KB
testcase_04 AC 124 ms
57,652 KB
testcase_05 WA -
testcase_06 WA -
testcase_07 WA -
testcase_08 AC 132 ms
57,968 KB
testcase_09 WA -
testcase_10 WA -
testcase_11 WA -
testcase_12 WA -
testcase_13 WA -
testcase_14 WA -
testcase_15 WA -
testcase_16 WA -
testcase_17 WA -
testcase_18 WA -
testcase_19 WA -
testcase_20 WA -
testcase_21 WA -
testcase_22 WA -
testcase_23 WA -
testcase_24 WA -
testcase_25 AC 137 ms
57,744 KB
testcase_26 AC 724 ms
75,728 KB
testcase_27 WA -
testcase_28 AC 139 ms
58,572 KB
testcase_29 AC 121 ms
57,520 KB
testcase_30 WA -
testcase_31 AC 600 ms
78,596 KB
testcase_32 WA -
testcase_33 WA -
testcase_34 WA -
testcase_35 WA -
testcase_36 WA -
testcase_37 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.util.*;

public class Main {
  static int N;
  static long[][] dat;

  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int n = sc.nextInt();
    init(n);
    int d = sc.nextInt();
    long k = sc.nextLong();
    long[] a = new long[n];
    for(int i = 0; i < n; i++) {
      a[i] = sc.nextLong();
      update(i, a[i]);
    }

    long ans = 0;
    int p = 0;
    long m1 = 0;
    long m2 = 0;
    for(int i = 0; i < n - 1; i++) {
      long[] t = query(i + 1, Math.min(i + d + 1, N), 0, 0, N);
      if(ans < k * (t[0] - a[i])) {
        p++;
        ans = k * (t[0] - a[i]);
        m1 = i;
        m2 = t[1];
        break;
      }
    }

    if(p == 0) {
      System.out.println(0);
    } else {
      System.out.println(ans);
      System.out.print(m1 + " " + m2);
    }
  }

  public static void init(int n_) {
    int n = 1;
    while(n < n_) {
      n *= 2;
    }
    N = n;
    dat = new long[2 * N - 1][2];
  }

  public static void update(long k, long x) {
    int a = (int)(k + N - 1);
    dat[a][0] = x;
    dat[a][1] = k;
    while(a > 0) {
      a = (a - 1) / 2;
      if(dat[2 * a + 1][0] >= dat[2 * a + 2][0]) {
        dat[a][0] = dat[2 * a + 1][0];
        dat[a][1] = dat[2 * a + 1][1];
      } else {
        dat[a][0] = dat[2 * a + 2][0];
        dat[a][1] = dat[2 * a + 2][1];
      }
    }
  }

  public static long[] query(int a, int b, int k, int l, int r) {
    long[] ret = new long[2];
    if((r <= a) || (l >= b)) {
      ret[0] = 0;
      ret[1] = -1;
      return ret;
    }
    if((a <= l) && (r <= b)) {
      ret[0] = dat[k][0];
      ret[1] = dat[k][1];
      return ret;
    } else {
      long[] vl = query(a, b, 2 * k + 1, l, (l + r) / 2);
      long[] vr = query(a, b, 2 * k + 2, (l + r) / 2, r);
      if(vl[0] >= vr[0]) {
        ret[0] = vl[0];
        ret[1] = vl[1];
      } else {
        ret[0] = vr[0];
        ret[1] = vr[1];
      }
      return ret;
    }
  }
}
0