結果

問題 No.489 株に挑戦
ユーザー kurenai3110kurenai3110
提出日時 2017-02-25 00:05:15
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 133 ms / 1,000 ms
コード長 1,207 bytes
コンパイル時間 670 ms
コンパイル使用メモリ 78,244 KB
実行使用メモリ 8,036 KB
最終ジャッジ日時 2023-09-27 05:13:33
合計ジャッジ時間 3,483 ms
ジャッジサーバーID
(参考情報)
judge14 / judge12
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 51 ms
4,380 KB
testcase_01 AC 52 ms
4,900 KB
testcase_02 AC 2 ms
4,380 KB
testcase_03 AC 1 ms
4,384 KB
testcase_04 AC 1 ms
4,380 KB
testcase_05 AC 2 ms
4,380 KB
testcase_06 AC 2 ms
4,380 KB
testcase_07 AC 2 ms
4,376 KB
testcase_08 AC 2 ms
4,380 KB
testcase_09 AC 2 ms
4,380 KB
testcase_10 AC 2 ms
4,380 KB
testcase_11 AC 2 ms
4,380 KB
testcase_12 AC 2 ms
4,376 KB
testcase_13 AC 2 ms
4,380 KB
testcase_14 AC 1 ms
4,380 KB
testcase_15 AC 4 ms
4,380 KB
testcase_16 AC 57 ms
4,380 KB
testcase_17 AC 6 ms
4,380 KB
testcase_18 AC 34 ms
4,380 KB
testcase_19 AC 29 ms
4,380 KB
testcase_20 AC 100 ms
5,424 KB
testcase_21 AC 22 ms
4,380 KB
testcase_22 AC 7 ms
4,376 KB
testcase_23 AC 31 ms
4,384 KB
testcase_24 AC 111 ms
5,484 KB
testcase_25 AC 1 ms
4,380 KB
testcase_26 AC 68 ms
7,624 KB
testcase_27 AC 29 ms
4,376 KB
testcase_28 AC 1 ms
4,380 KB
testcase_29 AC 1 ms
4,380 KB
testcase_30 AC 133 ms
7,976 KB
testcase_31 AC 71 ms
8,036 KB
testcase_32 AC 43 ms
4,380 KB
testcase_33 AC 111 ms
5,072 KB
testcase_34 AC 76 ms
4,380 KB
testcase_35 AC 31 ms
4,376 KB
testcase_36 AC 14 ms
4,376 KB
testcase_37 AC 58 ms
5,144 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <map>
using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)

int main()
{
	long long n, d, k; cin >> n >> d >> k;
	vector<int>x(n);
	for (int i = 0; i < n; i++) {
		cin >> x[i];
	}

	map<int,int>m;
	pair<int,int> ans = make_pair(0,0);
	for (int i = 0; i <= d;i++) {
		if (m.find(x[i]) == m.end()) {
			m[x[i]] = 1;
		}else m[x[i]]++;
	}

	auto fin = --m.end();
	ans = make_pair(fin->first - x[0], 0);
	for (int i = d + 1; i < n; i++) {
		m[x[i - d - 1]]--;
		if (m[x[i - d - 1]] == 0)m.erase(m.find(x[i - d - 1]));
		m[x[i]]++;
		auto fin = --m.end();
		if (ans.first < fin->first - x[i - d]) {
			ans = make_pair(fin->first - x[i - d], i - d);
		}
	}
	for (int i = n - d - 1; i < n-1; i++) {
		m[x[i]]--;
		if (m[x[i]] == 0)m.erase(m.find(x[i]));
		auto fin = --m.end();
		if (ans.first < fin->first - x[i+1]) {
			ans = make_pair(fin->first - x[i+1], i+1);
		}
	}

	cout << (long long)ans.first*k << endl;
	if (ans.first) {
		for (int i = ans.second; i <= min(n-1,ans.second + d); i++) {
			if (x[i] - x[ans.second] == ans.first) {
				cout << ans.second << " " << i << endl;
				break;
			}
		}
	}

	return 0;
}

0