Submission #6851313


Source Code Expand

// {{{
#include <algorithm>
#include <array>
#include <bitset>
#include <cassert>
#include <cmath>
#include <cstdio>
#include <iostream>
#include <iterator>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <random>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <tuple>
#include <utility>
#include <vector>
// }}}

using namespace std;

using ll = long long;
using ull = unsigned long long;
using ld = long double;

static constexpr int mod = (int)1e9 + 7;
static constexpr int inf = 100100100;
static constexpr ll linf = 1e18;
static constexpr double eps = 1e-9;
static constexpr double pi = 3.14159265359;

#define rep(i, n) for (ll i = 0; i < n; ++i)
#define rrep(i, n) for (ll i = n; i >= 0; --i)
#define all(c) begin(c), end(c)
#define rall(c) rbegin(c), rend(c)
#define pb push_back
#define ist insert
#define fst first
#define snd second


int main() {
    // cin.tie(0);
    // ios_base::sync_with_stdio(false);
    ll N, K;
    cin >> N >> K;
    deque<ll> d;
    rep (i, N) {
        ll v;
        cin >> v;
        d.pb(v);
    }
    ll M = min(N, K);
    ll ans = -linf;
    for (ll a = 0; a <= M; ++a) {
        for (ll b = 0; a + b <= M; ++b) {
            auto q = d;
            vector<ll> v;
            rep (i, a) {
                v.pb(q.front());
                q.pop_front();
            }
            rep (i, b) {
                v.pb(q.back());
                q.pop_back();
            }
            sort(all(v));
            ll c = 0;
            ll tmp = 0;
            for (ll i : v) {
                if (i < 0 && a + b + c < K) {
                    ++c;
                    continue;
                }
                tmp += i;
            }
            ans = max(ans, tmp);
        }
    }
    cout << ans << endl;
}

Submission Info

Submission Time
Task D - equeue
User gochiusa
Language C++14 (Clang 3.8.0)
Score 400
Code Size 1892 Byte
Status AC
Exec Time 3 ms
Memory 256 KiB

Judge Result

Set Name All Sample
Score / Max Score 400 / 400 0 / 0
Status
AC × 23
AC × 3
Set Name Test Cases
All sample_01, sample_02, sample_03, testcase_01, testcase_02, testcase_03, testcase_04, testcase_05, testcase_06, testcase_07, testcase_08, testcase_09, testcase_10, testcase_11, testcase_12, testcase_13, testcase_14, testcase_15, testcase_16, testcase_17, testcase_18, testcase_19, testcase_20
Sample sample_01, sample_02, sample_03
Case Name Status Exec Time Memory
sample_01 AC 1 ms 256 KiB
sample_02 AC 1 ms 256 KiB
sample_03 AC 1 ms 256 KiB
testcase_01 AC 1 ms 256 KiB
testcase_02 AC 1 ms 256 KiB
testcase_03 AC 1 ms 256 KiB
testcase_04 AC 3 ms 256 KiB
testcase_05 AC 3 ms 256 KiB
testcase_06 AC 2 ms 256 KiB
testcase_07 AC 2 ms 256 KiB
testcase_08 AC 1 ms 256 KiB
testcase_09 AC 2 ms 256 KiB
testcase_10 AC 1 ms 256 KiB
testcase_11 AC 1 ms 256 KiB
testcase_12 AC 1 ms 256 KiB
testcase_13 AC 1 ms 256 KiB
testcase_14 AC 2 ms 256 KiB
testcase_15 AC 1 ms 256 KiB
testcase_16 AC 2 ms 256 KiB
testcase_17 AC 2 ms 256 KiB
testcase_18 AC 1 ms 256 KiB
testcase_19 AC 1 ms 256 KiB
testcase_20 AC 1 ms 256 KiB