結果

問題 No.489 株に挑戦
ユーザー PachicobuePachicobue
提出日時 2017-03-16 18:15:06
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 90 ms / 1,000 ms
コード長 2,679 bytes
コンパイル時間 525 ms
コンパイル使用メモリ 77,224 KB
実行使用メモリ 9,372 KB
最終ジャッジ日時 2023-09-27 05:39:13
合計ジャッジ時間 2,837 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 40 ms
4,384 KB
testcase_01 AC 42 ms
5,528 KB
testcase_02 AC 2 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,380 KB
testcase_06 AC 2 ms
4,376 KB
testcase_07 AC 1 ms
4,376 KB
testcase_08 AC 1 ms
4,376 KB
testcase_09 AC 1 ms
4,380 KB
testcase_10 AC 1 ms
4,380 KB
testcase_11 AC 1 ms
4,376 KB
testcase_12 AC 1 ms
4,376 KB
testcase_13 AC 2 ms
4,380 KB
testcase_14 AC 2 ms
4,376 KB
testcase_15 AC 3 ms
4,376 KB
testcase_16 AC 67 ms
6,520 KB
testcase_17 AC 5 ms
4,380 KB
testcase_18 AC 28 ms
4,376 KB
testcase_19 AC 29 ms
4,804 KB
testcase_20 AC 72 ms
6,692 KB
testcase_21 AC 16 ms
4,460 KB
testcase_22 AC 6 ms
4,376 KB
testcase_23 AC 26 ms
4,376 KB
testcase_24 AC 84 ms
6,632 KB
testcase_25 AC 1 ms
4,376 KB
testcase_26 AC 56 ms
8,768 KB
testcase_27 AC 41 ms
4,924 KB
testcase_28 AC 1 ms
4,380 KB
testcase_29 AC 1 ms
4,376 KB
testcase_30 AC 90 ms
9,372 KB
testcase_31 AC 55 ms
9,300 KB
testcase_32 AC 33 ms
4,380 KB
testcase_33 AC 78 ms
6,292 KB
testcase_34 AC 56 ms
4,892 KB
testcase_35 AC 23 ms
4,460 KB
testcase_36 AC 11 ms
4,376 KB
testcase_37 AC 42 ms
5,944 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

// clang-format off
#include <cassert>
#include <iostream>
#include <vector>
#include <algorithm>
#include <utility>
#include <functional>
#include <set>

#define FOR(i, a, b) for(int i = (a); i < (b); i++)
#define RFOR(i, a, b) for(int i = (b)-1; i >= (a); i--)
#define rep(i, n) for(int i = 0; i < (n); i++)
#define rep1(i,n) for(int i = 1; i <= (n); i++)
#define rrep(i, n) for(int i = (n)-1; i >= 0; i--)

#define pb push_back
#define mp make_pair
#define fst first
#define snd second
#define show(x) cout << #x << " = " << x << endl
#define chmin(x,y) x=min(x,y)
#define chmax(x,y) x=max(x,y)
#define pii pair<int, int>
#define vi vector<int>

using namespace std;
template<class S,class T> ostream& operator<<(ostream& o,const pair<S,T>& p){return o<<"("<<p.first<<","<<p.second<<")";}
template<class T> ostream& operator<<(ostream& o,const vector<T>& vc){o<<"sz = "<<vc.size()<<endl<<"[";for(const T& v:vc) o<<v<<",";o<<"]";return o;}
typedef long long ll;

#define MAX 100000
int N, D, K;
int x[MAX];
pii ben[MAX];

std::function<bool(const pii&, const pii&)> comp = [](const pii& a, const pii& b)->bool
{
    if(a.fst < b.fst){
        return true;
    } else if(a.fst > b.fst){
        return false;
    } else {
        if(a.snd > b.snd){
            return true;
        } else if (a.snd < b.snd){
            return false;
        } else {
            return false;
        }
    }
};

int main()
{
    cin >> N >> D >> K;
    rep(i, N){
        cin >> x[i];
    }
    //    vector<pii> mask(D+1);
    set<pii, decltype(comp)> mask(comp);
    for(int i = 0; i <= D; i++){
        mask.insert(mp(x[i], i));
        //        mask[i] = mp(x[i], i);
    }
    // [x[i-D-1],...,x[i-1]], x[i]
    for(int i = D+1; i < N; i++){
        //        sort(mask.begin(), mask.end(), comp);
        ben[i-D-1] = mp(mask.rbegin()->fst - x[i-D-1], mask.rbegin()->snd);
        auto ite = mask.lower_bound(mp(x[i-D-1], i-D-1));
        mask.erase(ite);
        //        mask.pb(mp(x[i], i));
        mask.insert(mp(x[i], i));
    }
    // [x[j],...,x[N-1]]
    // [x[N-D-1],...,x[N-1]]
    for(int j = N-D-1; j < N; j++){
        //        sort(mask.begin(), mask.end(), comp);
        ben[j] = mp(mask.rbegin()->fst - x[j], mask.rbegin()->snd);
        auto ite = mask.lower_bound(mp(x[j], j));
        mask.erase(ite);
    }

    int max = 0;
    int max_i = 0;
    rep(i, N){
        if(max < ben[i].fst){
            max = ben[i].fst;
            max_i = i;
        }
    }
    if(ben[max_i].fst == 0){
        cout << 0 << endl;
    } else {
        cout << (ll)(ben[max_i].fst) * (ll)(K) << endl;
        cout << max_i << " " << ben[max_i].snd << endl;
    }
    return 0;
}
0