Submission #172301

#TimeUsernameProblemLanguageResultExecution timeMemory
172301arnold518Candies (JOI18_candies)C++14
8 / 100
35 ms31996 KiB
#include <bits/stdc++.h>
using namespace std;

typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

const int MAXN = 2000;
const ll INF = 1e16;

int N, A[MAXN+10];
ll dp[MAXN+10][MAXN+10];

int main()
{
    int i, j;

    scanf("%d", &N);
    for(i=1; i<=N; i++) scanf("%d", &A[i]);

    for(i=0; i<=N; i++) for(j=0; j<=N; j++) dp[i][j]=-INF;
    dp[1][1]=A[1];
    for(i=0; i<=N; i++) dp[i][0]=0;
    for(i=2; i<=N; i++)
    {
        for(j=1; j<=(N+1)/2; j++)
        {
            dp[i][j]=max(dp[i-1][j], dp[i-2][j-1]+A[i]);
        }
    }
    for(i=1; i<=(N+1)/2; i++) printf("%lld\n", dp[N][i]);
}

Compilation message (stderr)

candies.cpp: In function 'int main()':
candies.cpp:18:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     scanf("%d", &N);
     ~~~~~^~~~~~~~~~
candies.cpp:19:30: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     for(i=1; i<=N; i++) scanf("%d", &A[i]);
                         ~~~~~^~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...