Submission #63597533
Source Code Expand
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define all(x) (x).begin(), (x).end()
template<template<typename> class Container, typename G>
ostream& operator<<(ostream& os, Container<G> x) {
int f = 0; os << '{'; for (auto &i: x) os << (f++ ? ", " : ""), os << i; os << "}";
return os;
}
void _print() {cerr << "]\n";}
template<typename T, typename... V>
void _print(T t, V... v) {cerr << t; if (sizeof...(v)) cerr <<", "; _print(v...);}
#ifdef DEBUG
#define dbg(x...) cerr << "\e[91m"<<__func__<<":"<<__LINE__<<" [" << #x << "] = ["; _print(x); cerr << "\e[39m" << endl;
#else
#define dbg(x...)
#endif
#define pii pair<int, int>
#define f first
#define s second
int32_t main() {
int n;cin>>n;vector<int> a(n);for(int i=0;i<n;i++)cin>>a[i];
int o=0,e=-1e18;
vector<int> dp(n);
for(int i=0;i<n;i++){
if(i%2==0){
dp[i] = o+a[i];
e=max(e, dp[i]);
} else {
dp[i] = e+a[i];
o=max(o,dp[i]);
}
dbg(i,dp[i]);
}
int ans=dp[n-1];
if(n%2==0){
ans = max(ans, o);
} else {
ans = max(ans, e);
}
cout<<ans<<"\n";
}
Submission Info
| Submission Time | |
|---|---|
| Task | A - Operations on a Stack |
| User | justinlgl20 |
| Language | C++ 20 (gcc 12.2) |
| Score | 400 |
| Code Size | 1129 Byte |
| Status | AC |
| Exec Time | 59 ms |
| Memory | 6324 KiB |
Judge Result
| Set Name | Sample | All | ||||
|---|---|---|---|---|---|---|
| Score / Max Score | 0 / 0 | 400 / 400 | ||||
| Status |
|
|
| Set Name | Test Cases |
|---|---|
| Sample | example0.txt, example1.txt, example2.txt |
| All | 000.txt, 001.txt, 002.txt, 003.txt, 004.txt, 005.txt, 006.txt, 007.txt, 008.txt, 009.txt, 010.txt, 011.txt, 012.txt, 013.txt, 014.txt, 015.txt, 016.txt, 017.txt, 018.txt, 019.txt, 020.txt, 021.txt, 022.txt, 023.txt, 024.txt, example0.txt, example1.txt, example2.txt |
| Case Name | Status | Exec Time | Memory |
|---|---|---|---|
| 000.txt | AC | 1 ms | 3488 KiB |
| 001.txt | AC | 1 ms | 3484 KiB |
| 002.txt | AC | 55 ms | 6280 KiB |
| 003.txt | AC | 55 ms | 6260 KiB |
| 004.txt | AC | 55 ms | 6276 KiB |
| 005.txt | AC | 55 ms | 6324 KiB |
| 006.txt | AC | 59 ms | 6188 KiB |
| 007.txt | AC | 1 ms | 3480 KiB |
| 008.txt | AC | 1 ms | 3560 KiB |
| 009.txt | AC | 1 ms | 3488 KiB |
| 010.txt | AC | 29 ms | 4692 KiB |
| 011.txt | AC | 10 ms | 3628 KiB |
| 012.txt | AC | 23 ms | 4424 KiB |
| 013.txt | AC | 31 ms | 4972 KiB |
| 014.txt | AC | 32 ms | 4948 KiB |
| 015.txt | AC | 54 ms | 6268 KiB |
| 016.txt | AC | 54 ms | 6292 KiB |
| 017.txt | AC | 54 ms | 6232 KiB |
| 018.txt | AC | 54 ms | 6216 KiB |
| 019.txt | AC | 54 ms | 6184 KiB |
| 020.txt | AC | 53 ms | 6212 KiB |
| 021.txt | AC | 54 ms | 6220 KiB |
| 022.txt | AC | 54 ms | 6280 KiB |
| 023.txt | AC | 54 ms | 6192 KiB |
| 024.txt | AC | 53 ms | 6220 KiB |
| example0.txt | AC | 1 ms | 3488 KiB |
| example1.txt | AC | 1 ms | 3460 KiB |
| example2.txt | AC | 1 ms | 3492 KiB |