Submission #12199930
Source Code Expand
#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 KiB |
Judge Result
| Set Name |
Sample |
FULL |
| Score / Max Score |
0 / 0 |
500 / 500 |
| Status |
|
|
| 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 KiB |
| Sample_02.txt |
AC |
2 ms |
3508 KiB |
| Sample_03.txt |
AC |
2 ms |
3488 KiB |
| maxhand_01.txt |
AC |
27 ms |
35224 KiB |
| maxhand_02.txt |
AC |
27 ms |
35092 KiB |
| maxhand_03.txt |
AC |
29 ms |
35256 KiB |
| maxhand_04.txt |
AC |
26 ms |
35092 KiB |
| maxhand_05.txt |
AC |
30 ms |
35256 KiB |
| maxrand_01.txt |
AC |
26 ms |
35076 KiB |
| maxrand_02.txt |
AC |
27 ms |
35260 KiB |
| maxrand_03.txt |
AC |
29 ms |
35212 KiB |
| maxrand_04.txt |
AC |
32 ms |
35228 KiB |
| maxrand_05.txt |
AC |
28 ms |
35220 KiB |
| minhand_01.txt |
AC |
2 ms |
3660 KiB |
| minhand_02.txt |
AC |
2 ms |
3500 KiB |
| minhand_03.txt |
AC |
2 ms |
3628 KiB |
| minhand_04.txt |
AC |
2 ms |
3524 KiB |
| minrand_01.txt |
AC |
1 ms |
3600 KiB |
| minrand_02.txt |
AC |
2 ms |
3584 KiB |
| minrand_03.txt |
AC |
2 ms |
3668 KiB |
| minrand_04.txt |
AC |
2 ms |
3668 KiB |
| ni_01.txt |
AC |
2 ms |
3672 KiB |
| rand_01.txt |
AC |
13 ms |
15192 KiB |
| rand_02.txt |
AC |
27 ms |
33148 KiB |
| rand_03.txt |
AC |
20 ms |
27500 KiB |
| rand_04.txt |
AC |
6 ms |
6448 KiB |