結果

問題 No.489 株に挑戦
ユーザー どららどらら
提出日時 2017-02-24 23:42:44
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 37 ms / 1,000 ms
コード長 1,323 bytes
コンパイル時間 2,107 ms
コンパイル使用メモリ 152,144 KB
実行使用メモリ 6,756 KB
最終ジャッジ日時 2023-09-27 05:12:19
合計ジャッジ時間 3,659 ms
ジャッジサーバーID
(参考情報)
judge13 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 26 ms
4,380 KB
testcase_01 AC 18 ms
4,376 KB
testcase_02 AC 2 ms
4,376 KB
testcase_03 AC 1 ms
4,380 KB
testcase_04 AC 1 ms
4,380 KB
testcase_05 AC 1 ms
4,380 KB
testcase_06 AC 1 ms
4,376 KB
testcase_07 AC 2 ms
4,380 KB
testcase_08 AC 2 ms
4,380 KB
testcase_09 AC 1 ms
4,380 KB
testcase_10 AC 2 ms
4,376 KB
testcase_11 AC 2 ms
4,376 KB
testcase_12 AC 2 ms
4,380 KB
testcase_13 AC 1 ms
4,380 KB
testcase_14 AC 1 ms
4,376 KB
testcase_15 AC 3 ms
4,376 KB
testcase_16 AC 26 ms
5,408 KB
testcase_17 AC 5 ms
4,380 KB
testcase_18 AC 15 ms
4,380 KB
testcase_19 AC 13 ms
4,380 KB
testcase_20 AC 32 ms
5,188 KB
testcase_21 AC 10 ms
4,380 KB
testcase_22 AC 4 ms
4,380 KB
testcase_23 AC 19 ms
4,376 KB
testcase_24 AC 36 ms
5,640 KB
testcase_25 AC 1 ms
4,376 KB
testcase_26 AC 33 ms
6,756 KB
testcase_27 AC 31 ms
4,972 KB
testcase_28 AC 1 ms
4,376 KB
testcase_29 AC 1 ms
4,380 KB
testcase_30 AC 37 ms
6,064 KB
testcase_31 AC 33 ms
6,080 KB
testcase_32 AC 19 ms
4,380 KB
testcase_33 AC 35 ms
5,232 KB
testcase_34 AC 29 ms
4,620 KB
testcase_35 AC 13 ms
4,376 KB
testcase_36 AC 6 ms
4,380 KB
testcase_37 AC 20 ms
4,644 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
#define REP(i,a,n) for(int i=(a); i<(int)(n); i++)
#define rep(i,n) REP(i,0,n)
#define FOR(it,c) for(__typeof((c).begin()) it=(c).begin(); it!=(c).end(); ++it)
#define ALLOF(c) (c).begin(), (c).end()
typedef long long ll;
typedef unsigned long long ull;

//x.size() > k
//ret[i] == 0 if x.size()-k+1<=i
vector<ll> slide_max(const vector<ll>& x, int k){
  vector<ll> ret(x.size(), 0);
  deque<ll> deq;
  for(int i=0; i<x.size(); i++){
    while(deq.size()>0 && x[deq[deq.size()-1]]<=x[i]) deq.pop_back();
    deq.push_back(i);
    
    if(i-k+1 >= 0){
      ret[i-k+1] = x[deq[0]];
      if(deq[0] == i-k+1) deq.pop_front();
    }
  }
  return ret;
}

int main(){
  ll N, D, K;
  cin >> N >> D >> K;
  vector<ll> x;
  rep(i,N){
    ll a;
    cin >> a;
    x.push_back(a);
  }
  D++;
  rep(i,D){
    x.push_back(0);
  }
  
  vector<ll> mx = slide_max(x, D);
  
  ll best = 0;
  int best_i = 0;
  rep(i,N){
    //cout << x[i] << " " << mx[i] << endl;
    if(mx[i]-x[i]>best){
      best = mx[i]-x[i];
      best_i = i;
    }
  }
  if(best == 0){
    cout << 0 << endl;
  }else{
    cout << best*K << endl;
    cout << best_i << " ";
    REP(i,best_i,best_i+D){
      if(x[i] == mx[best_i]){
        cout << i;
        break;
      }
    }
    cout << endl;
  }

  
  return 0;
}

0