結果

問題 No.489 株に挑戦
ユーザー noynote
提出日時 2017-02-25 00:01:18
言語 C++11(廃止可能性あり)
(gcc 13.3.0)
結果
WA  
実行時間 -
コード長 1,227 bytes
コンパイル時間 1,502 ms
コンパイル使用メモリ 162,636 KB
実行使用メモリ 8,576 KB
最終ジャッジ日時 2025-01-03 00:56:41
合計ジャッジ時間 3,960 ms
ジャッジサーバーID
(参考情報)
judge5 / judge4
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 16 WA * 19
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp: In function ‘int main()’:
main.cpp:41:39: warning: ‘day[0]’ may be used uninitialized [-Wmaybe-uninitialized]
   41 |     if(dif * k > 0) cout << day[0] << ' ' << day[1] << endl;
      |                                       ^~~
main.cpp:20:9: note: ‘day[0]’ was declared here
   20 |     int day[2];
      |         ^~~
main.cpp:41:51: warning: ‘day[1]’ may be used uninitialized [-Wmaybe-uninitialized]
   41 |     if(dif * k > 0) cout << day[0] << ' ' << day[1] << endl;
      |                                                   ^
main.cpp:20:9: note: ‘day[1]’ was declared here
   20 |     int day[2];
      |         ^~~

ソースコード

diff #

#include<bits/stdc++.h>
#define range(i,a,b) for(int i = (a); i < (b); i++)
#define rep(i,b) for(int i = 0; i < (b); i++)
#define all(a) (a).begin(), (a).end()
#define show(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;
const int INF = 2000000000;
using namespace std;


int main(){
    int n, d, k;
    int a[100005];
    cin >> n >> d >> k;
    rep(i,n) cin >> a[i];
    d++;

    set<pair<int, int>> s;
    int i = 0, dif = 0;
    int day[2];
    while(true){
        if(i != n){
            s.insert(make_pair(a[i],i));
            i++;
        }else if(i == n && s.size() == 1) break;

        int temp = (--s.end())->first - a[i - s.size()];
        //for(auto it:s){ cout << it.second<< endl; }
        //show(s.size()) show( s.begin()->first); show( (--s.end())->first);
        if(temp > dif){
            dif = temp;
            day[0] = i - s.size();
            day[1] = (--s.end())->second;
        }
        //show(a[i - d])
        if(s.size() == d || i == n) s.erase(s.find(make_pair(a[i - s.size()], i - s.size())));
    }


    cout << dif * k << endl;
    if(dif * k > 0) cout << day[0] << ' ' << day[1] << endl;
}
0