結果

問題 No.489 株に挑戦
ユーザー takeya_okinotakeya_okino
提出日時 2019-07-06 15:16:39
言語 Java21
(openjdk 21)
結果
AC  
実行時間 819 ms / 1,000 ms
コード長 1,948 bytes
コンパイル時間 3,735 ms
コンパイル使用メモリ 84,916 KB
実行使用メモリ 80,336 KB
最終ジャッジ日時 2023-09-27 06:06:26
合計ジャッジ時間 20,287 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 739 ms
78,012 KB
testcase_01 AC 553 ms
65,468 KB
testcase_02 AC 147 ms
56,560 KB
testcase_03 AC 149 ms
56,456 KB
testcase_04 AC 121 ms
55,712 KB
testcase_05 AC 151 ms
57,004 KB
testcase_06 AC 156 ms
56,940 KB
testcase_07 AC 159 ms
56,904 KB
testcase_08 AC 147 ms
56,764 KB
testcase_09 AC 162 ms
57,140 KB
testcase_10 AC 160 ms
56,928 KB
testcase_11 AC 159 ms
56,944 KB
testcase_12 AC 160 ms
55,108 KB
testcase_13 AC 158 ms
54,980 KB
testcase_14 AC 155 ms
56,836 KB
testcase_15 AC 258 ms
61,100 KB
testcase_16 AC 733 ms
80,336 KB
testcase_17 AC 307 ms
60,500 KB
testcase_18 AC 535 ms
66,908 KB
testcase_19 AC 490 ms
65,228 KB
testcase_20 AC 742 ms
79,624 KB
testcase_21 AC 403 ms
62,620 KB
testcase_22 AC 294 ms
61,260 KB
testcase_23 AC 575 ms
64,964 KB
testcase_24 AC 819 ms
79,492 KB
testcase_25 AC 131 ms
55,456 KB
testcase_26 AC 739 ms
76,144 KB
testcase_27 AC 784 ms
79,272 KB
testcase_28 AC 153 ms
56,756 KB
testcase_29 AC 120 ms
56,108 KB
testcase_30 AC 792 ms
79,304 KB
testcase_31 AC 762 ms
80,220 KB
testcase_32 AC 588 ms
65,156 KB
testcase_33 AC 799 ms
79,508 KB
testcase_34 AC 735 ms
79,828 KB
testcase_35 AC 484 ms
63,144 KB
testcase_36 AC 338 ms
60,776 KB
testcase_37 AC 552 ms
64,916 KB
権限があれば一括ダウンロードができます

ソースコード

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];
      }
    }

    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