Untitled
unknown
c_cpp
5 months ago
1.5 kB
3
Indexable
#ifdef LOCAL # define _GLIBCXX_DEBUG #else # define cerr __get_ce #endif #include <bits/stdc++.h> #define ff first #define ss second #define szof(x) ((int)x.size()) using namespace std; typedef long long ll; typedef long double ld; typedef pair<int, int> pii; typedef unsigned long long ull; typedef pair<ll, ll> pll; int const INF = (int)1e9 + 1e3; ll const INFL = (ll)1e18 + 1e6; #ifdef LOCAL mt19937 tw(9450189); #else mt19937 tw(chrono::high_resolution_clock::now().time_since_epoch().count()); #endif uniform_int_distribution<ll> ll_distr; ll rnd(ll a, ll b) { return ll_distr(tw) % (b - a + 1) + a; } void solve() { int n; cin >> n; vector<vector<int>> inp; for (int i = 0; i < 2; ++i) { inp.push_back(vector<int>()); for (int j = 0; j < n; ++j) { int num; cin >> num; inp[i].push_back(num); } } pll d = {0, 0}; for (int i = 0; i < n; ++i) { pll next = {max(d.ff, d.ss + inp[0][i]), max(d.ss, d.ff + inp[1][i])}; d = next; } cout << max(d.ff, d.ss) << "\n"; } int main() { #ifdef LOCAL auto start_time = clock(); cerr << setprecision(3) << fixed; #endif cout << setprecision(15) << fixed; ios::sync_with_stdio(false); cin.tie(nullptr); int test_count = 1; // cin >> test_count; for (int test = 1; test <= test_count; ++test) { solve(); } #ifdef LOCAL auto end_time = clock(); cerr << "Execution time: " << (end_time - start_time) * (int)1e3 / CLOCKS_PER_SEC << " ms\n"; #endif }
Editor is loading...
Leave a Comment