結果

問題 No.489 株に挑戦
ユーザー uenokuuenoku
提出日時 2017-03-27 22:11:00
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 2,464 bytes
コンパイル時間 895 ms
コンパイル使用メモリ 101,484 KB
実行使用メモリ 7,304 KB
最終ジャッジ日時 2023-09-20 14:41:01
合計ジャッジ時間 3,902 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 WA -
testcase_01 WA -
testcase_02 AC 1 ms
4,376 KB
testcase_03 AC 2 ms
4,380 KB
testcase_04 AC 2 ms
4,376 KB
testcase_05 AC 2 ms
4,380 KB
testcase_06 WA -
testcase_07 WA -
testcase_08 AC 2 ms
4,380 KB
testcase_09 AC 2 ms
4,376 KB
testcase_10 WA -
testcase_11 WA -
testcase_12 AC 1 ms
4,376 KB
testcase_13 WA -
testcase_14 WA -
testcase_15 WA -
testcase_16 AC 68 ms
5,512 KB
testcase_17 WA -
testcase_18 WA -
testcase_19 WA -
testcase_20 AC 73 ms
5,512 KB
testcase_21 AC 18 ms
4,380 KB
testcase_22 WA -
testcase_23 WA -
testcase_24 WA -
testcase_25 AC 2 ms
4,376 KB
testcase_26 AC 74 ms
5,888 KB
testcase_27 WA -
testcase_28 AC 1 ms
4,376 KB
testcase_29 AC 2 ms
4,384 KB
testcase_30 AC 76 ms
6,264 KB
testcase_31 AC 73 ms
7,144 KB
testcase_32 WA -
testcase_33 WA -
testcase_34 WA -
testcase_35 WA -
testcase_36 AC 11 ms
4,384 KB
testcase_37 AC 43 ms
4,380 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include "math.h"
#include <algorithm>
#include <complex>
#include <cstdio>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <string>
#include <vector>
#define ifor(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 rrep(i, n) for (int i = (n)-1; i >= 0; i--)
using namespace std;
using lli = long long int;
lli MOD = 1000000007;
template <class T>
class segtree
{
public:
    lli n;
    vector<T> dat;
    function<T(T, T)> func;
    T dummy;
    segtree<T>(lli _n, T ini, function<T(T, T)> f, T dummy) : func(f), dummy(dummy)
    {
        n = 1;
        while (n < _n) {
            n = n * 2;
        }
        dat.assign(2 * n - 1, ini);
    }
    void update(lli k, T a)
    {
        k += n - 1;
        dat[k] = a;
        while (k > 0) {
            k = (k - 1) / 2;
            dat[k] = func(dat[k * 2 + 1], dat[k * 2 + 2]);
        }
    }
    T query(int a, int b)
    {
        return query(a, b, 0, 0, n);
    }
    // [a,b)の何かを求める.
    T query(int a, int b, int k, int l, int r)
    {
        //交差しないときはダミー
        if (r <= a || b <= l)
            return dummy;
        if (a <= l && r <= b)
            return dat[k];
        else {
            T vl = query(a, b, k * 2 + 1, l, (l + r) / 2);
            T vr = query(a, b, k * 2 + 2, (l + r) / 2, r);
            return func(vl, vr);
        }
    }
    T get(int a)
    {
        return query(a, a + 1, 0, 0, n);
    }
};
struct node {
    lli l, r, c;
};
int main()
{
    auto f = [](lli a, lli b) -> lli { return max(a, b); };
    lli first = (1LL << 50) - 1LL;
    lli n, d, k;
    cin >> n >> d >> k;
    segtree<lli> seg(n + 10, -first, f, -first);
    lli ans = 0;
    lli a[1000005];
    rep(i, n)
    {
        cin >> a[i];
        seg.update(i, a[i]);
    }
    d++;
    lli fir = 0;
    rep(i, n)
    {
        lli temp = seg.query(i, min(i + d, n)) * k - a[i] * k;
        if (ans < temp) {
            fir = i;
        }
        ans = max(ans, seg.query(i, min(i + d, n)) * k - a[i] * k);
    }

    cout << ans << endl;
    if (ans == 0)
        return 0;
    else {
        int end = 0;
        rep(i, d + 1)
        {
            if (a[i] * k - a[fir] * k == ans) {
                end = i;
                break;
            }
        }
        cout << fir << ' ' << end << endl;
    }
}
0