# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
47837 | TheDarkning | Candies (JOI18_candies) | C++17 | 956 ms | 395448 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
/**
▄█▀ ▀█▀ ▄▀▄ █▀ █▄█▄█ ▄▀▄ █▀ ▄█▀
<⇋⇋⇋⋛∰≓⊂(⌒,_ゝ⌒)⊃≓∰⋛⇋⇋⇋>
♔♕♖♗♘♙ ☜❷☞✪ ィℋ६ ≈ ᗫẵℜℵĬŊĞ ✪☜❷☞ ♚♛♜♝♞♟
♔♕♖♗♘♙ ♚♛♜♝♞♟
˙·٠•●♥ Ƹ̵̡Ӝ̵̨̄Ʒ ♥●•٠·˙
916 921 919 673
**/
#include <iostream>
#include <cstdio>
#include <vector>
#include <algorithm>
#include <iomanip>
#include <time.h>
#include <map>
#include <deque>
#include <assert.h>
#include <queue>
#include <string>
#include <memory.h>
#include <set>
#include <math.h>
#define sz(s) s.size()
#define pb emplace_back
#define fr first
#define sc second
#define mk make_pair
#define int long long
#define all(s) s.begin(), s.end()
#define ok puts("ok");
using namespace std;
const int N = 2e5 + 5;
const int inf = 1e18 + 7;
int n, ar[N], dp[5000][5000];
main(){
cin >> n;
for( int i = 1; i <= n; i++ ){
scanf("%d", &ar[i]);
}
for( int i = 0; i <= n; i++ ){
for( int j = 0; j <= n; j++ ){
dp[ i ][ j ] = -inf;
}
}
dp[ 0 ][ 0 ] = 0;
dp[ 0 ][ 1 ] = 0;
dp[ 1 ][ 1 ] = ar[ 1 ];
for( int i = 2; i <= n; i++ ){
int cur = 0;
for( int j = 0; j <= i; j++ ){
cur = dp[j][ i - 1 ];
if( j )
cur = max( cur, dp[ j - 1 ][ i - 2 ] + ar[ i ] );
dp[ j ][ i ] = cur;
}
}
for( int i = 1; i <= ( n + 1 ) / 2; i++ ){
cout << dp[ i ][ n ] << endl;
}
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |