結果

問題 No.489 株に挑戦
ユーザー alpha_virginisalpha_virginis
提出日時 2017-03-12 16:18:43
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 17 ms / 1,000 ms
コード長 2,833 bytes
コンパイル時間 1,525 ms
コンパイル使用メモリ 176,052 KB
実行使用メモリ 6,608 KB
最終ジャッジ日時 2023-09-27 05:38:54
合計ジャッジ時間 3,138 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 12 ms
5,828 KB
testcase_01 AC 8 ms
4,712 KB
testcase_02 AC 1 ms
4,380 KB
testcase_03 AC 1 ms
4,380 KB
testcase_04 AC 1 ms
4,376 KB
testcase_05 AC 2 ms
4,380 KB
testcase_06 AC 1 ms
4,380 KB
testcase_07 AC 1 ms
4,380 KB
testcase_08 AC 1 ms
4,376 KB
testcase_09 AC 1 ms
4,380 KB
testcase_10 AC 1 ms
4,376 KB
testcase_11 AC 2 ms
4,376 KB
testcase_12 AC 1 ms
4,380 KB
testcase_13 AC 1 ms
4,380 KB
testcase_14 AC 2 ms
4,376 KB
testcase_15 AC 2 ms
4,376 KB
testcase_16 AC 13 ms
6,080 KB
testcase_17 AC 3 ms
4,380 KB
testcase_18 AC 8 ms
4,724 KB
testcase_19 AC 7 ms
4,404 KB
testcase_20 AC 15 ms
6,092 KB
testcase_21 AC 5 ms
4,376 KB
testcase_22 AC 3 ms
4,376 KB
testcase_23 AC 10 ms
4,892 KB
testcase_24 AC 16 ms
6,384 KB
testcase_25 AC 1 ms
4,376 KB
testcase_26 AC 15 ms
6,520 KB
testcase_27 AC 15 ms
6,608 KB
testcase_28 AC 1 ms
4,380 KB
testcase_29 AC 1 ms
4,376 KB
testcase_30 AC 17 ms
6,288 KB
testcase_31 AC 15 ms
6,236 KB
testcase_32 AC 10 ms
5,044 KB
testcase_33 AC 17 ms
6,348 KB
testcase_34 AC 14 ms
6,036 KB
testcase_35 AC 7 ms
4,376 KB
testcase_36 AC 4 ms
4,376 KB
testcase_37 AC 10 ms
5,040 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>

#ifndef LOCAL_
#define fprintf if( false ) fprintf
#endif // LOCAL_
#define dumpi(x1) fprintf(stderr, "#%s.%d (%s) = (%d)\n", __func__, __LINE__, #x1, x1);
#define dumpii(x1, x2) fprintf(stderr, "#%s.%d (%s, %s) = (%d, %d)\n", __func__, __LINE__, #x1, #x2, x1, x2);
#define dumpiii(x1, x2, x3) fprintf(stderr, "#%s.%d (%s, %s, %s) = (%d, %d, %d)\n", __func__, __LINE__, #x1, #x2, #x3, x1, x2, x3);
#define dumpl(x1) fprintf(stderr, "#%s.%d (%s) = (%ld)\n", __func__, __LINE__, #x1, x1);
#define dumpll(x1, x2) fprintf(stderr, "#%s.%d (%s, %s) = (%ld, %ld)\n", __func__, __LINE__, #x1, #x2, x1, x2);
#define dumpd(x1) fprintf(stderr, "#%s.%d (%s) = (%lf)\n", __func__, __LINE__, #x1, x1);
#define dumpdd(x1, x2) fprintf(stderr, "#%s.%d (%s, %s) = (%lf, %lf)\n", __func__, __LINE__, #x1, #x2, x1, x2);

struct S002 {
  int n;
  S002& operator > (long& x) {
    n = x;
    return *this;
  }
  S002& operator >= (long& x) {
    if( scanf("%ld", &x) <= 0 ) exit(0);
    return *this;
  }
  S002& operator >= (double& x) {
    if( scanf("%lf", &x) <= 0 ) exit(0);
    return *this;
  }
  S002& operator >= (std::string& s) {
    if( not (std::cin >> s) ) exit(0);
    return *this;
  }
  template<typename a>
  S002& operator >= (std::vector<a>& v) {
    v.resize(n);
    for(long i = 0; i < n; ++i) {
      *this >= v[i];
    }
    return *this;
  }
};

template<typename a>
struct S003 {
  std::vector<a> ys;
  S003(std::vector<a> xs, long k, long s) {
    long n = xs.size();
    ys.resize(n);
    std::deque<a> q;
    for(long i = 0; i < n + k - 1; ++i) {
      if( i < n ) {
        while( not q.empty() and s * xs[q.back()] <= s * xs[i]) q.pop_back();
        q.push_back(i);
      }
      long w = i - k + 1;
      if( w >= 0 ) {
        ys[w] = xs[q.front()];
        if( q.front() == w ) q.pop_front();
      }
    }
  }
  typename std::vector<a>::iterator begin() {
    return ys.begin();
  }
  typename std::vector<a>::iterator end() {
    return ys.end();
  }
  size_t size() {
    return ys.size();
  }
  a operator [] (int i) {
    return ys[i];
  }
};

struct Solver {
  long n, d, k;
  std::vector<long> xs;
  Solver() {
    S002 r;
    r >= n >= d >= k >n>= xs;
  }
  void solve() {
    S003<long> s(xs, d + 1, 1);
    std::vector<long> zs;
    for(int i = 0; i < (int)s.size(); ++i) {
      zs.push_back(s[i] - xs[i]);
    }
    long max = *std::max_element(zs.begin(), zs.end());
    auto it = std::find(zs.begin(), zs.end(), max);
    long x = it - zs.begin();
    auto it2 = std::find(xs.begin() + x, xs.end(), xs[x] + max);
    long y = it2 - xs.begin();
    if( max * k == 0 ) {
      puts("0");
      return;
    }
    printf("%ld\n", max * k);
    printf("%ld %ld\n", x, y);
  }  
};

int main() {
  for(;;) {
    std::unique_ptr<Solver> s(new Solver());
    s->solve();
  }
  return 0;
}
0