Submission #765181

# Submission time Handle Problem Language Result Execution time Memory
765181 2023-06-24T09:09:38 Z LucaIlie Homecoming (BOI18_homecoming) C++17
0 / 100
28 ms 17864 KB
#include <bits/stdc++.h>
#include "homecoming.h"

using namespace std;

const long long INF = 1e16;
const int MAX_N = 5000;
long long dp[MAX_N + 1][MAX_N + 1];

long long solve( int n, int k, int a[], int b[] ) {
    long long ans = -INF;

    for ( int l = 0; l <= k; l++ ) {
        //printf( "PENTRU K = %d\n\n", l );

        for ( int j = 0; j <= l; j++ )
            dp[n + 1][j] = 0;
        for ( int j = l + 1; j <= k; j++ )
            dp[n + 1][j] = -INF;

        for ( int i = n; i >= 1; i-- ) {
            dp[i][0] = -INF;
            if ( i > l ) {
                for ( int j = 0; j <= k; j++ )
                    dp[i][0] = max( dp[i][0], dp[i + 1][j] );
            }

            for ( int j = 1; j < k; j++ )
                dp[i][j] = dp[i + 1][j - 1] - b[i];

            dp[i][k] = max( dp[i + 1][k - 1], dp[i + 1][k] ) - b[i] + a[i];
        }

        /*for ( int i = n; i >= 1; i-- ) {
            printf( "i = %d\n", i );
            for ( int j = 0; j <= k; j++ )
                printf( "%d ", dp[i][j] );
            printf( "\n" );
        }*/

        for ( int j = 0; j <= k; j++ )
            ans = max( ans, dp[1][j] );
    }

    return ans;
}
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 724 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 724 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 28 ms 17864 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 724 KB Output isn't correct
2 Halted 0 ms 0 KB -