結果
問題 |
No.919 You Are A Project Manager
|
ユーザー |
![]() |
提出日時 | 2019-10-26 13:32:18 |
言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 2,890 ms / 3,000 ms |
コード長 | 2,364 bytes |
コンパイル時間 | 1,144 ms |
コンパイル使用メモリ | 112,764 KB |
実行使用メモリ | 6,944 KB |
最終ジャッジ日時 | 2024-09-14 06:56:24 |
合計ジャッジ時間 | 55,886 ms |
ジャッジサーバーID (参考情報) |
judge6 / judge1 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 55 |
ソースコード
// #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; cin >> N; vector< pair<ll, ll> > A(N); for(int i=0; i<N; i++) { ll v; cin >> 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(b >= B) continue; 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(b >= B) continue; 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])); } } cout << ans << endl; return 0; }