結果

問題 No.919 You Are A Project Manager
ユーザー tsutajtsutaj
提出日時 2019-10-26 13:34:39
言語 C++14
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 2,177 ms / 3,000 ms
コード長 2,316 bytes
コンパイル時間 1,226 ms
コンパイル使用メモリ 111,316 KB
実行使用メモリ 6,820 KB
最終ジャッジ日時 2024-12-20 10:47:20
合計ジャッジ時間 47,183 ms
ジャッジサーバーID
(参考情報)
judge3 / judge5
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 55
権限があれば一括ダウンロードができます

ソースコード

diff #

// #define _GLIBCXX_DEBUG // for STL debug (optional)
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <string>
#include <cstring>
#include <deque>
#include <list>
#include <queue>
#include <stack>
#include <vector>
#include <utility>
#include <algorithm>
#include <map>
#include <set>
#include <complex>
#include <cmath>
#include <limits>
#include <cfloat>
#include <climits>
#include <ctime>
#include <cassert>
#include <numeric>
#include <fstream>
#include <functional>
#include <bitset>
using namespace std;
using ll = long long int;
using int64 = long long int;
 
template<typename T> void chmax(T &a, T b) {a = max(a, b);}
template<typename T> void chmin(T &a, T b) {a = min(a, b);}
template<typename T> void chadd(T &a, T b) {a = a + b;}
 
int dx[] = {0, 0, 1, -1};
int dy[] = {1, -1, 0, 0};
const int INF = 1LL << 29;
const ll LONGINF = 1LL << 60;
const ll MOD = 1000000007LL;
 
int main() {
    int N; scanf("%d", &N);
    vector< pair<ll, ll> > A(N);
    for(int i=0; i<N; i++) {
        ll v; scanf("%lld", &v);
        A[i] = make_pair(v, i);
    }

    sort(A.begin(), A.end());
    vector<ll> L(N), R(N), CL(N), CR(N);

    ll ans = 0;
    for(int K=1; K<=N; K++) {
        int B = N / K;
        fill(L.begin(), L.begin() + B, 0);
        fill(R.begin(), R.begin() + B, 0);

        int half = (K + 1) / 2;
        for(int i=0; i<N; i++) {
            int b = A[i].second / K;
            if(++L[b] == half) CL[b] = A[i].first;
        }
        for(int i=0; i<N; i++) {
            int b = (N - 1 - A[i].second) / K;
            if(++R[b] == half) CR[b] = A[i].first;
        }

        for(int i=1; i<B; i++) {
            CL[i] += CL[i-1];
            CR[i] += CR[i-1];
        }
        for(int i=1; i<B; i++) {
            chmax(CL[i], CL[i-1]);
            chmax(CR[i], CR[i-1]);
        }

        chmax(ans, K * max(CL[B-1], CR[B-1]));

        // l: [ K*l, K*(l+1) )
        // r: (N-1-K*(r+1) , N-1-K*r]
        // bl - ar は -1 以上であれば OK
        int l, r = B-1;
        for(l=0; l<B; l++) {
            int al = K*l, ar = K*(l+1);
            int bl = N-1-K*(r+1), br = N-1-K*r;
            while(r >= 0 and bl - ar < -1) r--, bl += K, br += K;
            if(r >= 0) chmax(ans, K * (CL[l] + CR[r]));
        }
    }
    printf("%lld\n", ans);
    return 0;
}
0