# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
1124375 | seoul_korea | Candies (JOI18_candies) | C++17 | 46 ms | 16348 KiB |
#include <bits/stdc++.h>
using namespace std;
#define TASK "JOI18_candies"
#define int long long
#define REP(i, n) for(int i = 1; i <= n; i++)
#define FOR(i, a, b) for(auto i = a; i <= b; i++)
#define FORD(i, a, b) for(auto i = a; i >= b; i--)
template<class T> bool maximize(T& a, T b) { if(a < b) return a = b, 1; return 0; }
template<class T> bool minimize(T& a, T b) { if(a > b) return a = b, 1; return 0; }
mt19937 rng(time(0));
const int N = (int)2e5 + 7;
int a[N];
int n;
namespace Subtask1
{
const int maxN = 2007;
int f[maxN][maxN];
bool Check()
{
return n <= 2000;
}
void Calc(int k)
{
REP(i, n)
{
if(f[i - 1][k]) f[i][k] = f[i - 1][k];
if(i - 2 > 0 && f[i - 2][k - 1]) maximize(f[i][k], f[i - 2][k - 1] + a[i]);
}
}
void Solve()
{
REP(i, n)
f[i][1] = max(a[i], f[i - 1][1]);
REP(i, (n + 1) / 2)
{
if(i > 1) Calc(i);
int ans = 0;
REP(j, n)
maximize(ans, f[j][i]);
cout << ans << '\n';
}
}
}
signed main(void)
{
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
if(fopen("TASK.INP", "r")) freopen("TASK.INP", "r", stdin);
if(fopen(TASK".INP", "r"))
{
freopen(TASK".INP", "r", stdin);
freopen(TASK".OUT", "w", stdout);
}
cin >> n;
REP(i, n)
cin >> a[i];
if(Subtask1::Check()) return Subtask1::Solve(), 0;
return 0;
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |