結果

問題 No.489 株に挑戦
ユーザー nmnmnmnmnmnmnmnmnmnmnmnmnmnm
提出日時 2017-02-24 22:57:02
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 57 ms / 1,000 ms
コード長 2,656 bytes
コンパイル時間 580 ms
コンパイル使用メモリ 90,352 KB
実行使用メモリ 12,536 KB
最終ジャッジ日時 2023-09-27 05:02:56
合計ジャッジ時間 2,754 ms
ジャッジサーバーID
(参考情報)
judge15 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 43 ms
12,196 KB
testcase_01 AC 27 ms
6,760 KB
testcase_02 AC 1 ms
5,704 KB
testcase_03 AC 1 ms
5,684 KB
testcase_04 AC 2 ms
5,404 KB
testcase_05 AC 2 ms
5,464 KB
testcase_06 AC 2 ms
5,488 KB
testcase_07 AC 2 ms
5,428 KB
testcase_08 AC 2 ms
5,428 KB
testcase_09 AC 2 ms
5,488 KB
testcase_10 AC 2 ms
5,460 KB
testcase_11 AC 2 ms
5,532 KB
testcase_12 AC 2 ms
5,416 KB
testcase_13 AC 2 ms
5,408 KB
testcase_14 AC 2 ms
5,524 KB
testcase_15 AC 4 ms
5,920 KB
testcase_16 AC 47 ms
12,260 KB
testcase_17 AC 8 ms
5,800 KB
testcase_18 AC 26 ms
6,872 KB
testcase_19 AC 20 ms
6,776 KB
testcase_20 AC 53 ms
12,328 KB
testcase_21 AC 14 ms
6,036 KB
testcase_22 AC 6 ms
5,676 KB
testcase_23 AC 28 ms
6,848 KB
testcase_24 AC 57 ms
12,528 KB
testcase_25 AC 2 ms
5,408 KB
testcase_26 AC 53 ms
12,328 KB
testcase_27 AC 56 ms
12,184 KB
testcase_28 AC 2 ms
5,464 KB
testcase_29 AC 2 ms
5,428 KB
testcase_30 AC 55 ms
12,536 KB
testcase_31 AC 54 ms
12,252 KB
testcase_32 AC 32 ms
6,756 KB
testcase_33 AC 57 ms
12,264 KB
testcase_34 AC 51 ms
12,344 KB
testcase_35 AC 20 ms
6,756 KB
testcase_36 AC 8 ms
5,868 KB
testcase_37 AC 30 ms
6,764 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <algorithm>
#include <cfloat>
#include <climits>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <functional>
#include <iostream>
#include <map>
#include <memory>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>

using namespace std;

typedef long long ll;

#define sz size()
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define all(c) (c).begin(), (c).end()
#define rep(i,a,b) for(ll i=(a);i<(b);++i)
#define per(i,a,b) for(ll i=(b-1);i>=(a);--i)
#define clr(a, b) memset((a), (b) ,sizeof(a))
#define ctos(c) string(1,c)
#define print(x) cout<<#x<<" = "<<x<<endl;

#define MOD 1000000007

#define N_MAX (1<<20)
#define INF 1000000000000LL

int nn_mn;
long long dat_mn[(2 * N_MAX) - 1];

void init_mn(int n1){
  nn_mn = 1;

  while(nn_mn < n1)nn_mn *= 2;

  for(int i = 0; i < 2 * nn_mn - 1; i++){
    dat_mn[i] = INF;
  }
}

void update_mn(int k, long long a){
  k += nn_mn - 1;
  dat_mn[k] = a;
  while(k > 0){
    k = (k - 1) / 2;
    dat_mn[k] = min(dat_mn[k * 2 + 1], dat_mn[k * 2 + 2]);
  }
}

long long query_mn(int a, int b, int k, int l, int r){
  if(r <= a || b <= l)return INF;

  if(a <= l && r <= b){
    return dat_mn[k];
  }
  else{
    long long vl = query_mn(a, b, k * 2 + 1, l, (l + r) / 2);
    long long vr = query_mn(a, b, k * 2 + 2, (l + r) / 2, r);
    return min(vl, vr);
  }
}

int nn_mx;
long long dat_mx[(2 * N_MAX) - 1];

void init_mx(int n1){
  nn_mx = 1;

  while(nn_mx < n1)nn_mx *= 2;

  for(int i = 0; i < 2 * nn_mx - 1; i++){
    dat_mx[i] = -INF;
  }
}

void update_mx(int k, long long a){
  k += nn_mx - 1;
  dat_mx[k] = a;
  while(k > 0){
    k = (k - 1) / 2;
    dat_mx[k] = max(dat_mx[k * 2 + 1], dat_mx[k * 2 + 2]);
  }
}

long long query_mx(int a, int b, int k, int l, int r){
  if(r <= a || b <= l)return -INF;

  if(a <= l && r <= b){
    return dat_mx[k];
  }
  else{
    long long vl = query_mx(a, b, k * 2 + 1, l, (l + r) / 2);
    long long vr = query_mx(a, b, k * 2 + 2, (l + r) / 2, r);
    return max(vl, vr);
  }
}

int main() {
	ll n,d,k;
	cin>>n>>d>>k;
	vector<ll> v;
	init_mn(n);
	init_mx(n);
	rep(i,0,n){
		ll a;
		cin>>a;
		v.pb(a);
		update_mn(i,a);
		update_mx(i,a);
	}
	ll mx = 0;
	ll index = -1;
	rep(i,0,n-1){
		ll a = query_mx(i+1,min(n,i+d+1),0,0,nn_mx)-v[i];
		if(mx<a){
			mx = max(mx,a);
			index = i;
		}
	}
	if(mx==0){
		cout << 0 << endl;
		return 0;
	}
	ll index2 = -1;
	rep(i,index,n){
		if(v[i]-v[index]==mx){
			index2=i;
			break;
		}
	}
	cout << mx*k << endl;
	cout << index << " " << index2 << endl;
	return 0;
}
0