結果

問題 No.489 株に挑戦
ユーザー 1119_29161119_2916
提出日時 2017-02-25 00:30:02
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 85 ms / 1,000 ms
コード長 2,900 bytes
コンパイル時間 1,360 ms
コンパイル使用メモリ 156,476 KB
実行使用メモリ 12,008 KB
最終ジャッジ日時 2023-09-27 05:18:17
合計ジャッジ時間 3,969 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 64 ms
11,948 KB
testcase_01 AC 44 ms
11,572 KB
testcase_02 AC 5 ms
11,748 KB
testcase_03 AC 5 ms
11,608 KB
testcase_04 AC 5 ms
11,564 KB
testcase_05 AC 5 ms
11,532 KB
testcase_06 AC 5 ms
11,568 KB
testcase_07 AC 4 ms
11,564 KB
testcase_08 AC 5 ms
11,548 KB
testcase_09 AC 4 ms
11,552 KB
testcase_10 AC 5 ms
11,536 KB
testcase_11 AC 5 ms
11,756 KB
testcase_12 AC 6 ms
11,620 KB
testcase_13 AC 5 ms
11,564 KB
testcase_14 AC 4 ms
11,676 KB
testcase_15 AC 7 ms
11,572 KB
testcase_16 AC 66 ms
11,808 KB
testcase_17 AC 12 ms
11,668 KB
testcase_18 AC 40 ms
11,608 KB
testcase_19 AC 32 ms
11,616 KB
testcase_20 AC 74 ms
11,856 KB
testcase_21 AC 21 ms
11,552 KB
testcase_22 AC 11 ms
11,676 KB
testcase_23 AC 44 ms
11,560 KB
testcase_24 AC 84 ms
11,880 KB
testcase_25 AC 5 ms
11,544 KB
testcase_26 AC 84 ms
11,852 KB
testcase_27 AC 85 ms
11,900 KB
testcase_28 AC 5 ms
11,744 KB
testcase_29 AC 5 ms
11,616 KB
testcase_30 AC 73 ms
11,860 KB
testcase_31 AC 70 ms
11,880 KB
testcase_32 AC 47 ms
11,584 KB
testcase_33 AC 83 ms
11,876 KB
testcase_34 AC 76 ms
12,008 KB
testcase_35 AC 33 ms
11,664 KB
testcase_36 AC 15 ms
11,640 KB
testcase_37 AC 46 ms
11,576 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
 
using namespace std;
 
#define INF 1001000100010001000
#define MOD 1000000007
#define RMQ_SIZE 262144
#define EPS 1e-10
#define int long long
#define rep(i, N) for (int i = 0; i < N; i++)
#define Rep(i, N) for (int i = 1; i < N; i++)
#define For(i, a, b) for (int i = (a); i < (b); i++)
#define pb push_back
#define mp make_pair
#define i_i pair<int, int>
#define vi vector<int>
#define vvi vector<vi >
#define vb vector<bool>
#define vvb vector<vb >
#define vp vector< i_i >
#define all(a) (a).begin(), (a).end()
#define Int(x) int x; scanf("%lld", &x);
#define int2(x, y) int x, y; scanf("%lld %lld", &x, &y);
 
//int dxy[5] = {0, 1, 0, -1, 0};
// assign

class segtree
{
    private:
        i_i dfs(int a,int b,int k,int l,int r)
        {
            //* 要求範囲を含まないレンジの探索.
            if (r <= a || b <= l) {
                return mp(INF, -1);
            }
            //* 木のレンジが要求範囲以下になる時.
            if (a <= l && r <= b) {
                return tree[k];
            }
            int m = (l+r)/2;
            return min(dfs(a, b, k*2+1, l, m), dfs(a, b, k*2+2, m, r));
        }

        i_i min(i_i a, i_i b)
        {
            if (a.first < b.first) {
                return a;
            } else if (a.first > b.first) {
                return b;
            } else if (a.second < b.second) {
                return a;
            } else {
                return b;
            }
        }

    public:
        int size;
        i_i *tree;

        segtree(int c) {
            size = 262144;
            tree = (i_i *)malloc(sizeof(i_i)*size);
            for (int i = 0; i < size; i++) {
                tree[i] = mp(c, i);
            }
        }

        i_i getMin(int right, int left)
        {
            return dfs(right, left, 0, 0, RMQ_SIZE/2);
        }

        void update(int pos, int value)
        {
            pos += (RMQ_SIZE/2 -1);
            tree[pos].first = value;
            while (pos) {
                pos = (pos-1)/2;
                tree[pos] = min(tree[pos*2+1], tree[pos*2+2]);
            }
        }
};


signed main()
{
    int a, b, c;
    cin >> a >> b >> c;
    vi input(a, 0);
    segtree mi(INF), ma(-INF);

    rep(i, a) {
        cin >> input[i];
        mi.update(i, input[i]);
        ma.update(i, -input[i]);
    }

    int ans = 0;
    i_i ret;

    rep(i, a) {
        i_i d = mi.getMin(i, min(i+b+1, a)), 
            e = ma.getMin(i, min(i+b+1, a));
        //cout << d.second << " " << e.second << endl;
        if (ans < -e.first - input[i]) {
            ans = -e.first - input[i];
            ret.first = i;
            ret.second = e.second - 262144/2 + 1;
        }
    }
    if (ans) {
    cout << ans * c << endl;
    cout << ret.first << " " << ret.second << endl;
    } else {
        cout << 0 << endl;
    }
    
    return 0;
}


0