Untitled

 avatar
unknown
plain_text
5 months ago
1.4 kB
10
Indexable
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
void File() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr), cout.tie(nullptr);
#ifdef MON
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
    freopen("errors.txt", "w", stderr);
#else
#endif
}
array<ll, 2> solve(vector<ll> a, function<array<ll, 2>(array<ll, 2>, array<ll, 2>)> comp) {
    int n = a.size();
    vector<array<ll, 2>> lis(n);
    array<ll, 2> ans = {0, 0};
    for (int i = 0; i < n; ++i) {
        lis[i] = {1, a[i]};
        for (int j = 0; j < i; ++j) {
            if (a[j] < a[i]) {
                lis[i] = comp(lis[i], {lis[j][0] + 1, lis[j][1] + a[i]});
            }
        }
        ans = comp(ans, lis[i]);
    }
    return ans;
}
void SolveTestCases(int tc) {
    int n;
    cin >> n;
    vector<ll> a(n);
    for (auto &x: a) cin >> x;
    auto [lis_sz, lis_sum] = solve(a, [&](array<ll, 2> a, array<ll, 2> b) {
        return max(a, b);
    });
    for (auto &X: a) X *= -1;
    auto [lds_sz, lds_sum] = solve(a, [&](array<ll, 2> a, array<ll, 2> b) {
        if (a[0] == b[0]) return min(a, b);
        return max(a, b);
    });
    cout << lis_sz << ' ' << lis_sum << ' ' << lds_sz << ' ' << -lds_sum << '\n';
}
int main() {
    File();
    int tt = 1;
    for (int tc = 1; tc <= tt; ++tc) {
        SolveTestCases(tc);
    }
    return 0;
}
Editor is loading...
Leave a Comment