結果

問題 No.489 株に挑戦
ユーザー a_kawashiroa_kawashiro
提出日時 2017-12-27 20:54:07
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
RE  
実行時間 -
コード長 2,335 bytes
コンパイル時間 1,429 ms
コンパイル使用メモリ 122,324 KB
実行使用メモリ 10,080 KB
最終ジャッジ日時 2023-08-23 07:21:45
合計ジャッジ時間 5,956 ms
ジャッジサーバーID
(参考情報)
judge13 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 RE -
testcase_01 AC 43 ms
9,444 KB
testcase_02 AC 1 ms
4,376 KB
testcase_03 AC 1 ms
4,376 KB
testcase_04 AC 1 ms
4,376 KB
testcase_05 AC 1 ms
4,376 KB
testcase_06 AC 2 ms
4,376 KB
testcase_07 AC 2 ms
4,380 KB
testcase_08 AC 2 ms
4,380 KB
testcase_09 AC 2 ms
4,380 KB
testcase_10 AC 2 ms
4,376 KB
testcase_11 AC 2 ms
4,380 KB
testcase_12 AC 2 ms
4,380 KB
testcase_13 AC 2 ms
4,376 KB
testcase_14 AC 2 ms
4,380 KB
testcase_15 AC 4 ms
4,376 KB
testcase_16 RE -
testcase_17 AC 9 ms
4,540 KB
testcase_18 AC 29 ms
5,484 KB
testcase_19 AC 23 ms
5,344 KB
testcase_20 RE -
testcase_21 AC 17 ms
6,260 KB
testcase_22 AC 7 ms
4,504 KB
testcase_23 AC 47 ms
9,924 KB
testcase_24 RE -
testcase_25 AC 1 ms
4,380 KB
testcase_26 RE -
testcase_27 RE -
testcase_28 AC 1 ms
4,380 KB
testcase_29 AC 2 ms
4,376 KB
testcase_30 RE -
testcase_31 RE -
testcase_32 AC 50 ms
10,080 KB
testcase_33 RE -
testcase_34 RE -
testcase_35 AC 29 ms
7,704 KB
testcase_36 AC 11 ms
5,196 KB
testcase_37 AC 47 ms
9,804 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 100000

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[100000];
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