Submission #12131467


Source Code Expand

Copy
#include <cstdio>
#include <cstring>
#include <iostream>
#include <string>
#include <cmath>
#include <bitset>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <algorithm>
#include <complex>
#include <unordered_map>
#include <unordered_set>
#include <random>
#include <cassert>
#include <fstream>
#include <utility>
#include <functional>
#include <time.h>
#include <stack>
#include <array>
#define popcount __builtin_popcount
using namespace std;
typedef long long int ll;
typedef pair<ll, int> P;

int main()
{
    int n;
    cin>>n;
    vector<P> va(n);
    ll a[2020];
    for(int i=0; i<n; i++) cin>>a[i];
    for(int i=0; i<n; i++) va[i]=P(a[i], i);
    sort(va.begin(), va.end(), greater<P>());
    ll dp[2020][2020];
    for(int i=0; i<=n; i++) for(int j=0; j<=n-i; j++) dp[i][j]=-1e18;
    dp[0][0]=0;
    for(int i=0; i<=n; i++){
        for(int j=0; j<n-i; j++){
            ll a1=va[i+j].first, k=va[i+j].second;
            dp[i+1][j]=max(dp[i+1][j], abs(i-k)*a1+dp[i][j]);
            dp[i][j+1]=max(dp[i][j+1], abs(n-j-1-k)*a1+dp[i][j]);
        }
    }
    ll ans=-1e18;
    for(int i=0; i<=n; i++) ans=max(ans, dp[i][n-i]);
    cout<<ans<<endl;
	return 0;
}

Submission Info

Submission Time
Task E - Active Infants
User chocorusk
Language C++ (GCC 9.2.1)
Score 500
Code Size 1267 Byte
Status AC
Exec Time 24 ms
Memory 26372 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 5 ms 3676 KB
Sample_02.txt AC 2 ms 3664 KB
Sample_03.txt AC 2 ms 3636 KB
maxhand_01.txt AC 24 ms 26324 KB
maxhand_02.txt AC 23 ms 26372 KB
maxhand_03.txt AC 23 ms 26320 KB
maxhand_04.txt AC 24 ms 26280 KB
maxhand_05.txt AC 24 ms 26344 KB
maxrand_01.txt AC 24 ms 26248 KB
maxrand_02.txt AC 23 ms 26292 KB
maxrand_03.txt AC 23 ms 26320 KB
maxrand_04.txt AC 23 ms 26292 KB
maxrand_05.txt AC 23 ms 26320 KB
minhand_01.txt AC 2 ms 3548 KB
minhand_02.txt AC 2 ms 3640 KB
minhand_03.txt AC 2 ms 3624 KB
minhand_04.txt AC 2 ms 3484 KB
minrand_01.txt AC 2 ms 3456 KB
minrand_02.txt AC 2 ms 3592 KB
minrand_03.txt AC 2 ms 3520 KB
minrand_04.txt AC 2 ms 3484 KB
ni_01.txt AC 2 ms 3508 KB
rand_01.txt AC 14 ms 11420 KB
rand_02.txt AC 22 ms 24268 KB
rand_03.txt AC 16 ms 18696 KB
rand_04.txt AC 4 ms 5760 KB