結果

問題 No.489 株に挑戦
ユーザー rickythetarickytheta
提出日時 2017-02-24 22:38:02
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 15 ms / 1,000 ms
コード長 1,050 bytes
コンパイル時間 2,700 ms
コンパイル使用メモリ 147,092 KB
実行使用メモリ 4,384 KB
最終ジャッジ日時 2023-09-27 04:59:05
合計ジャッジ時間 4,946 ms
ジャッジサーバーID
(参考情報)
judge12 / judge11
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 12 ms
4,384 KB
testcase_01 AC 10 ms
4,380 KB
testcase_02 AC 2 ms
4,380 KB
testcase_03 AC 2 ms
4,380 KB
testcase_04 AC 1 ms
4,376 KB
testcase_05 AC 2 ms
4,380 KB
testcase_06 AC 2 ms
4,376 KB
testcase_07 AC 2 ms
4,380 KB
testcase_08 AC 2 ms
4,376 KB
testcase_09 AC 1 ms
4,376 KB
testcase_10 AC 2 ms
4,376 KB
testcase_11 AC 1 ms
4,376 KB
testcase_12 AC 2 ms
4,380 KB
testcase_13 AC 2 ms
4,376 KB
testcase_14 AC 2 ms
4,376 KB
testcase_15 AC 3 ms
4,376 KB
testcase_16 AC 11 ms
4,380 KB
testcase_17 AC 4 ms
4,380 KB
testcase_18 AC 7 ms
4,376 KB
testcase_19 AC 7 ms
4,376 KB
testcase_20 AC 14 ms
4,380 KB
testcase_21 AC 5 ms
4,380 KB
testcase_22 AC 3 ms
4,376 KB
testcase_23 AC 8 ms
4,376 KB
testcase_24 AC 14 ms
4,380 KB
testcase_25 AC 2 ms
4,380 KB
testcase_26 AC 14 ms
4,376 KB
testcase_27 AC 13 ms
4,380 KB
testcase_28 AC 2 ms
4,376 KB
testcase_29 AC 1 ms
4,376 KB
testcase_30 AC 15 ms
4,380 KB
testcase_31 AC 14 ms
4,380 KB
testcase_32 AC 9 ms
4,376 KB
testcase_33 AC 14 ms
4,376 KB
testcase_34 AC 12 ms
4,376 KB
testcase_35 AC 6 ms
4,376 KB
testcase_36 AC 3 ms
4,380 KB
testcase_37 AC 9 ms
4,376 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp: In function ‘int main()’:
main.cpp:49:11: warning: ‘b’ may be used uninitialized in this function [-Wmaybe-uninitialized]
     printf("%lld\n%d %d\n",ans,a,b);
     ~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
main.cpp:49:11: warning: ‘a’ may be used uninitialized in this function [-Wmaybe-uninitialized]

ソースコード

diff #

#include <bits/stdc++.h>

using namespace std;

typedef vector<int> vi;
typedef long long ll;
typedef pair<int,int> pii;

typedef int _loop_int;
#define REP(i,n) for(_loop_int i=0;i<(_loop_int)(n);++i)
#define FOR(i,a,b) for(_loop_int i=(_loop_int)(a);i<(_loop_int)(b);i++)
#define FORR(i,a,b) for(_loop_int i=(_loop_int)(b)-1;i>=(_loop_int)(a);--i)

#define ALL(a) (a).begin(),(a).end()
#define CHMIN(a,b) a=min((a),(b))
#define CHMAX(a,b) a=max((a),(b))

int n,d,k;
int x[125252];

void ins(deque<int> &Q, int i){
  if(i>=n)return;
  while(!Q.empty() && x[Q.back()]<x[i])Q.pop_back();
  Q.push_back(i);
}

int main(){
  scanf("%d%d%d",&n,&d,&k);
  REP(i,n)scanf("%d",x+i);
  deque<int> Q;
  REP(i,d+1)ins(Q,i);
  ll ans = -1;
  int a,b;
  REP(i,n){
    // buy at i
    ll buy = (ll)x[i]*k;
    ll sell = (ll)x[Q.front()]*k;
    if(sell-buy > ans){
      ans = sell-buy;
      a = i;
      b = Q.front();
    }
    if(Q.front()==i)Q.pop_front();
    ins(Q,i+d+1);
  }
  if(ans==0){
    puts("0");
  }else{
    printf("%lld\n%d %d\n",ans,a,b);
  }
}
0