結果

問題 No.919 You Are A Project Manager
ユーザー polyomino_24
提出日時 2019-10-26 22:44:53
言語 C++17
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 1,836 ms / 3,000 ms
コード長 2,302 bytes
コンパイル時間 1,254 ms
コンパイル使用メモリ 129,848 KB
最終ジャッジ日時 2025-01-08 01:59:12
ジャッジサーバーID
(参考情報)
judge1 / judge4
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 55
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <algorithm>
#include <cassert>
#include <cctype>
#include <climits>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstring>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <string>
#include <tuple>
#include <vector>
#include <list>
#define rep(i, n) for (int i = 0; i < (int)(n); ++i)
//#define cerr if(false) cerr
#ifdef DEBUG
#define show(...) cerr << #__VA_ARGS__ << " = ", debug(__VA_ARGS__);
#else
#define show(...) 42
#endif
using namespace std;
using ll = long long;
using pii = pair<int, int>;
template <typename T, typename S>
ostream& operator<<(ostream& os, pair<T, S> a) {
    os << '(' << a.first << ',' << a.second << ')';
    return os;
}
template <typename T>
ostream& operator<<(ostream& os, vector<T> v) {
    for (auto x : v) os << x << ' ';
    return os;
}
void debug() {
    cerr << '\n';
}
template <typename H, typename... T>
void debug(H a, T... b) {
    cerr << a;
    if (sizeof...(b)) cerr << ", ";
    debug(b...);
}
ll dp[2][10005];
ll rui[10005];
int main(){
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    int n;
    cin >> n;
    vector<int>a(n);
    rep(i,n)cin >> a[i];
    ll ans = -(1LL<<60);
    for(int k = 1; k <= n; k++){
        ll sum = 0;
        const int pos = (k - 1)/ 2;
        show(pos);
        int sz  = 0;
        auto b = a, c = a;
        for(int i = 0; i + k <= n; i+= k){
            nth_element(b.begin()+i, b.begin()+i+pos, b.begin()+i+k);
            dp[0][sz++] = ((ll)k * b[i+pos]);
        }
        sz = 0;
        for(int i = n; i - k >= 0; i-= k){
            nth_element(c.begin()+i-k, c.begin()+i-k+pos, c.begin()+i);
            dp[1][sz++] = ((ll)k * c[i-k+pos]);
        }
        rep(i,2){
            sum = max(sum,dp[i][0]);
            rep(j,sz-1){
                dp[i][j+1] += dp[i][j];
                sum = max(sum, dp[i][j+1]);
            }
        }
        rep(i,sz){
            if(i==0)rui[i] = dp[0][0];
            else rui[i] = max(rui[i-1], dp[0][i]);
        }
        rep(i,sz-1){
            sum = max(sum, rui[i] + dp[1][sz - 2 -i]);
        }
        show(k, sz, sum);
        ans = max(ans, sum);
    }
    cout << ans << endl;
}
0