結果

問題 No.919 You Are A Project Manager
コンテスト
ユーザー fine
提出日時 2019-10-26 02:53:50
言語 C++14
(gcc 15.2.0 + boost 1.89.0)
コンパイル:
g++-15 -O2 -lm -std=c++14 -Wuninitialized -DONLINE_JUDGE -o a.out _filename_
実行:
./a.out
結果
AC  
実行時間 1,438 ms / 3,000 ms
コード長 1,225 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 1,163 ms
コンパイル使用メモリ 188,264 KB
実行使用メモリ 6,400 KB
最終ジャッジ日時 2026-04-13 09:34:23
合計ジャッジ時間 22,773 ms
ジャッジサーバーID
(参考情報)
judge1_0 / judge2_0
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 55
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

#include <bits/stdc++.h>

using namespace std;

using ll = long long;

// 配列aの[start, end)の中でk番目に小さい値を求める
template<class T>
T select_kth(vector<T>& a, int start, int end, int k) {
    vector<T> v(a.begin() + start, a.begin() + end);
    nth_element(v.begin(), v.begin() + k, v.end());
    return v[k];
}

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n;
    cin >> n;
    vector<ll> a(n);
    for (int i = 0; i < n; i++) {
        cin >> a[i];
    }

    ll ans = 0;
    for (int k = 1; k <= n; k++) {
        int max_num = n / k;
        vector<ll> memoL(max_num + 1, 0);
        ll tmp = 0;
        for (int i = 0; i < max_num; i++) {
            tmp += select_kth(a, i * k, (i + 1) * k, (k - 1) / 2) * k;
            memoL[i + 1] = max(memoL[i], tmp);
        }

        vector<ll> memoR(max_num + 1, 0);

        tmp = 0;
        for (int i = 0; i < max_num; i++) {
            tmp += select_kth(a, n - (i + 1) * k, n - i * k, (k - 1) / 2) * k;
            memoR[i + 1] = max(memoR[i], tmp);
        }

        for (int i = 0; i <= max_num; i++) {
            ans = max(ans, memoL[i] + memoR[max_num - i]);
        }
    }
    cout << ans << "\n";
    return 0;
}
0