結果
問題 |
No.489 株に挑戦
|
ユーザー |
![]() |
提出日時 | 2017-03-27 22:14:32 |
言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 85 ms / 1,000 ms |
コード長 | 2,529 bytes |
コンパイル時間 | 1,093 ms |
コンパイル使用メモリ | 104,972 KB |
実行使用メモリ | 6,144 KB |
最終ジャッジ日時 | 2024-07-19 23:43:44 |
合計ジャッジ時間 | 3,352 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge5 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 35 |
ソースコード
#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 { lli end = 0; rep(i, d + 1) { if (i + fir >= n) break; if (a[i + fir] * k - a[fir] * k == ans) { end = i + fir; break; } } cout << fir << ' ' << end << endl; } }