結果
問題 | No.489 株に挑戦 |
ユーザー |
![]() |
提出日時 | 2017-02-24 22:38:02 |
言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
結果 |
AC
|
実行時間 | 15 ms / 1,000 ms |
コード長 | 1,050 bytes |
コンパイル時間 | 1,992 ms |
コンパイル使用メモリ | 163,588 KB |
実行使用メモリ | 5,376 KB |
最終ジャッジ日時 | 2024-07-19 22:55:22 |
合計ジャッジ時間 | 3,331 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge5 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 35 |
コンパイルメッセージ
main.cpp: In function ‘int main()’: main.cpp:28:8: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result] 28 | scanf("%d%d%d",&n,&d,&k); | ~~~~~^~~~~~~~~~~~~~~~~~~ main.cpp:29:16: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result] 29 | REP(i,n)scanf("%d",x+i); | ~~~~~^~~~~~~~~~
ソースコード
#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); } }