結果

問題 No.489 株に挑戦
ユーザー a_kawashiroa_kawashiro
提出日時 2017-12-27 20:55:40
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 104 ms / 1,000 ms
コード長 2,335 bytes
コンパイル時間 916 ms
コンパイル使用メモリ 97,148 KB
実行使用メモリ 15,896 KB
最終ジャッジ日時 2023-09-27 05:53:45
合計ジャッジ時間 3,695 ms
ジャッジサーバーID
(参考情報)
judge14 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 73 ms
12,932 KB
testcase_01 AC 42 ms
9,476 KB
testcase_02 AC 1 ms
4,380 KB
testcase_03 AC 2 ms
4,376 KB
testcase_04 AC 2 ms
4,376 KB
testcase_05 AC 2 ms
4,384 KB
testcase_06 AC 1 ms
4,376 KB
testcase_07 AC 2 ms
4,376 KB
testcase_08 AC 2 ms
4,376 KB
testcase_09 AC 1 ms
4,380 KB
testcase_10 AC 2 ms
4,376 KB
testcase_11 AC 1 ms
4,376 KB
testcase_12 AC 2 ms
4,376 KB
testcase_13 AC 1 ms
4,376 KB
testcase_14 AC 2 ms
4,380 KB
testcase_15 AC 4 ms
4,376 KB
testcase_16 AC 50 ms
6,556 KB
testcase_17 AC 8 ms
4,576 KB
testcase_18 AC 28 ms
5,764 KB
testcase_19 AC 23 ms
5,412 KB
testcase_20 AC 93 ms
13,964 KB
testcase_21 AC 17 ms
6,192 KB
testcase_22 AC 7 ms
4,564 KB
testcase_23 AC 48 ms
9,928 KB
testcase_24 AC 104 ms
15,468 KB
testcase_25 AC 1 ms
4,376 KB
testcase_26 AC 66 ms
15,896 KB
testcase_27 AC 35 ms
5,228 KB
testcase_28 AC 1 ms
4,380 KB
testcase_29 AC 2 ms
4,380 KB
testcase_30 AC 101 ms
15,528 KB
testcase_31 AC 67 ms
15,840 KB
testcase_32 AC 47 ms
9,892 KB
testcase_33 AC 99 ms
14,948 KB
testcase_34 AC 80 ms
13,624 KB
testcase_35 AC 28 ms
7,704 KB
testcase_36 AC 12 ms
5,176 KB
testcase_37 AC 47 ms
9,988 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <stack>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <string>
#include <vector>
#include <queue>
#include <map>
#include <set>
#include <tuple>
#include <algorithm>
#include <functional>
#include <cstring>
#include <limits.h>
#define FOR(i,k,n)  for (int i=(k); i<(int)(n); ++i)
#define REP(i,n)    FOR(i,0,n)
#define FORIT(i,c)	for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)
#define SZ(i) ((int)i.size())
#define GI(i) (scanf("%d",&i))
#define GLL(i) (scanf("%lld",&i))
#define GD(i)  (scanf("%lf",&i))
#define PB          push_back
#define MP          make_pair
#define MT          make_tuple
#define GET0(x)     (get<0>(x))
#define GET1(x)     (get<1>(x))
#define GET2(x)     (get<2>(x))
#define ALL(X)      (X).begin(),(X).end()
#define LLMAX       (1LL<<60)
#define LLMIN       -(1LL<<60)
#define IMAX        (1<<30)
#define IMIN        -(1<<30)
typedef long long LL;
using namespace std;

#define MAX 200000

class RangeMaxPointChange{
    public:
    int N, dat[2*MAX];
    RangeMaxPointChange(int n) {
        N = 1;
        while(N < n) N *= 2;
        for(int i = 0; i < 2*N-1; i++)
            dat[i] = IMIN;
    }
    // update k th element
    void update(int k, int a) {
        k += N-1; // leaf
        dat[k] = a;
        while(k > 0) {
            k = (k - 1) / 2;
            dat[k] = max(dat[k*2+1], dat[k*2+2]);
        }
    }
    // min [a, b)
    int query(int a, int b) { return query(a, b, 0, 0, N); }
    int query(int a, int b, int k, int l, int r) {
        if(r <= a or b <= l) return IMIN;
        if(a <= l and r <= b) return dat[k];
        int m = (l + r) / 2;
        return max(query(a, b, k*2+1, l, m), query(a, b, k*2+2, m, r));
    }
};

int N,D,K,x[200000];
map<int,vector<int> > id;

int main(void){
    GI(N);GI(D);GI(K);
    RangeMaxPointChange seg(N);
    REP(i,N){
        GI(x[i]);
        id[x[i]].PB(i);
        seg.update(i,x[i]);
    }
    LL m=0;
    int j,k;
    REP(i,N){
        int b = seg.query(i,min(N,i+D+1));
        // printf("i=%d b=%d D=%d\n",i,b,D);
        if(m < (LL)(b - x[i]) * (LL)K){
            m = (LL)(b - x[i]) * (LL)K;
            j = i;
            k = *lower_bound(ALL(id[b]),i+1);
        }
    }
    if(m==0)
        printf("%lld\n",m);
    else
        printf("%lld\n%d %d\n",m,j,k);
    return 0;
}
0