Submission #503665

#TimeUsernameProblemLanguageResultExecution timeMemory
503665fatemetmhrCandies (JOI18_candies)C++17
8 / 100
5095 ms3540 KiB
// ~Be name khoda~ // #include<bits/stdc++.h> using namespace std; typedef long long ll; #define pb push_back #define mp make_pair #define all(x) x.begin(), x.end() #define fi first #define se second #define cl clear #define endll '\n' const int maxn = 1e6 + 10; const int maxn5 = 5e5 + 10; const int maxnt = 1.2e6 + 10; const int maxn3 = 1e3 + 10; const int mod = 1e9 + 7; const ll inf = 2e18; ll dp[2][2][maxn5]; int main() { ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0); int n; cin >> n; for(int i = 0; i < n; i++){ int a; cin >> a; dp[i%2][0][0] = 0; for(int k = 1; k <= (i + 2) / 2; k++){ dp[i%2][0][k] = max(dp[(i + 1)%2][0][k], dp[(i + 1)%2][1][k]); dp[i%2][1][k] = k > 1 && dp[(i + 1)%2][0][k - 1] == 0 ? 0 : dp[(i + 1)%2][0][k - 1] + a; //cout << i << ' ' << k << ' ' << dp[i%2][0][k] << ' ' << dp[i%2][1][k] << '\n'; } } for(int i = 1; i <= (n + 1) / 2; i++) cout << max(dp[(n - 1)%2][0][i], dp[(n - 1)%2][1][i]) << '\n'; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...