結果

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

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 14 ms
6,332 KB
testcase_01 AC 9 ms
5,088 KB
testcase_02 AC 1 ms
4,376 KB
testcase_03 AC 2 ms
4,380 KB
testcase_04 AC 1 ms
4,380 KB
testcase_05 AC 2 ms
4,376 KB
testcase_06 AC 1 ms
4,380 KB
testcase_07 AC 1 ms
4,376 KB
testcase_08 AC 1 ms
4,380 KB
testcase_09 AC 2 ms
4,380 KB
testcase_10 AC 2 ms
4,376 KB
testcase_11 AC 1 ms
4,380 KB
testcase_12 AC 1 ms
4,376 KB
testcase_13 AC 2 ms
4,376 KB
testcase_14 AC 1 ms
4,376 KB
testcase_15 AC 2 ms
4,380 KB
testcase_16 AC 13 ms
6,704 KB
testcase_17 AC 4 ms
4,376 KB
testcase_18 AC 8 ms
5,060 KB
testcase_19 AC 6 ms
4,736 KB
testcase_20 AC 16 ms
6,772 KB
testcase_21 AC 5 ms
4,376 KB
testcase_22 AC 3 ms
4,380 KB
testcase_23 AC 9 ms
5,324 KB
testcase_24 AC 17 ms
7,212 KB
testcase_25 AC 2 ms
4,376 KB
testcase_26 AC 17 ms
7,432 KB
testcase_27 AC 15 ms
7,144 KB
testcase_28 AC 1 ms
4,380 KB
testcase_29 AC 1 ms
4,380 KB
testcase_30 AC 17 ms
7,328 KB
testcase_31 AC 15 ms
7,296 KB
testcase_32 AC 9 ms
5,408 KB
testcase_33 AC 16 ms
7,224 KB
testcase_34 AC 14 ms
6,488 KB
testcase_35 AC 6 ms
4,608 KB
testcase_36 AC 4 ms
4,380 KB
testcase_37 AC 9 ms
5,404 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 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 xs[q.back()] >= 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();
      }
    }
  }
};

struct Solver {
  long n, d, k;
  std::vector<long> xs;
  Solver() {
    S002 r;
    r >= n >= d >= k >n>= xs;
  }
  void solve() {
    std::vector<long> ys;
    std::transform(xs.begin(), xs.end(), std::back_inserter(ys),
                   [](long x){ return -x; });
    S003<long> s(ys, d + 1);
    std::vector<long> zs;
    for(int i = 0; i < (int)s.ys.size(); ++i) {
      zs.push_back((-s.ys[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