Submission #12199930


Source Code Expand

Copy
#include<bits/stdc++.h>
#define rep(i,a,b) for(int i=a;i<b;i++)
#define rrep(i,a,b) for(int i=a;i>=b;i--)
#define fore(i,a) for(auto &i:a)
#define all(x) (x).begin(),(x).end()
//#pragma GCC optimize ("-O3")
using namespace std; void _main(); int main() { cin.tie(0); ios::sync_with_stdio(false); _main(); }
typedef long long ll; const int inf = INT_MAX / 2; const ll infl = 1LL << 60;
template<class T>bool chmax(T& a, const T& b) { if (a < b) { a = b; return 1; } return 0; }
template<class T>bool chmin(T& a, const T& b) { if (b < a) { a = b; return 1; } return 0; }
//---------------------------------------------------------------------------------------------------
/*---------------------------------------------------------------------------------------------------
            ∧_∧
      ∧_∧  (´<_` )  Welcome to My Coding Space!
     ( ´_ゝ`) /  ⌒i     @hamayanhamayan0
    /   \     | |
    /   / ̄ ̄ ̄ ̄/  |
  __(__ニつ/     _/ .| .|____
     \/____/ (u ⊃
---------------------------------------------------------------------------------------------------*/














int N; ll A[2010];
ll dp[2020][2020];
//---------------------------------------------------------------------------------------------------
void _main() {
	cin >> N;
	rep(i, 0, N) cin >> A[i];

	vector<int> ord;
	rep(i, 0, N) ord.push_back(i);
	sort(all(ord), [&](int a, int b) { return A[a] > A[b]; });

	rep(tot, 0, N + 1) rep(lft, 0, N + 1) dp[tot][lft] = -inf;
	dp[0][0] = 0;

	rep(tot, 0, N) rep(lft, 0, tot + 1) if(0 <= dp[tot][lft]) {
		int i = ord[tot];

		if (0 <= i - lft) chmax(dp[tot + 1][lft + 1], dp[tot][lft] + A[i] * (i - lft));
		if (0 <= (N - 1 - (tot - lft) - i)) chmax(dp[tot + 1][lft], dp[tot][lft] + A[i] * (N - 1 - (tot - lft) - i));
	}

	ll ans = 0;
	rep(lft, 0, N + 1) chmax(ans, dp[N][lft]);
	cout << ans << endl;
}





Submission Info

Submission Time
Task E - Active Infants
User hamayanhamayan
Language C++ (GCC 9.2.1)
Score 500
Code Size 2054 Byte
Status AC
Exec Time 32 ms
Memory 35260 KB

Judge Result

Set Name Sample FULL
Score / Max Score 0 / 0 500 / 500
Status
AC × 3
AC × 26
Set Name Test Cases
Sample Sample_01.txt, Sample_02.txt, Sample_03.txt
FULL Sample_01.txt, Sample_02.txt, Sample_03.txt, maxhand_01.txt, maxhand_02.txt, maxhand_03.txt, maxhand_04.txt, maxhand_05.txt, maxrand_01.txt, maxrand_02.txt, maxrand_03.txt, maxrand_04.txt, maxrand_05.txt, minhand_01.txt, minhand_02.txt, minhand_03.txt, minhand_04.txt, minrand_01.txt, minrand_02.txt, minrand_03.txt, minrand_04.txt, ni_01.txt, rand_01.txt, rand_02.txt, rand_03.txt, rand_04.txt
Case Name Status Exec Time Memory
Sample_01.txt AC 9 ms 3640 KB
Sample_02.txt AC 2 ms 3508 KB
Sample_03.txt AC 2 ms 3488 KB
maxhand_01.txt AC 27 ms 35224 KB
maxhand_02.txt AC 27 ms 35092 KB
maxhand_03.txt AC 29 ms 35256 KB
maxhand_04.txt AC 26 ms 35092 KB
maxhand_05.txt AC 30 ms 35256 KB
maxrand_01.txt AC 26 ms 35076 KB
maxrand_02.txt AC 27 ms 35260 KB
maxrand_03.txt AC 29 ms 35212 KB
maxrand_04.txt AC 32 ms 35228 KB
maxrand_05.txt AC 28 ms 35220 KB
minhand_01.txt AC 2 ms 3660 KB
minhand_02.txt AC 2 ms 3500 KB
minhand_03.txt AC 2 ms 3628 KB
minhand_04.txt AC 2 ms 3524 KB
minrand_01.txt AC 1 ms 3600 KB
minrand_02.txt AC 2 ms 3584 KB
minrand_03.txt AC 2 ms 3668 KB
minrand_04.txt AC 2 ms 3668 KB
ni_01.txt AC 2 ms 3672 KB
rand_01.txt AC 13 ms 15192 KB
rand_02.txt AC 27 ms 33148 KB
rand_03.txt AC 20 ms 27500 KB
rand_04.txt AC 6 ms 6448 KB