제출 #1340456

#제출 시각아이디문제언어결과실행 시간메모리
1340456iamhereforfunFeast (NOI19_feast)C++20
0 / 100
32 ms5072 KiB
// Starcraft 2 enjoyer //

#include <bits/stdc++.h>

// #pragma GCC target("avx2")
// #pragma GCC optimize("O3")
// #pragma GCC optimize("unroll-loops")

using namespace std;

#define LSOne(X) ((X) & -(X))

const int N = 3e5 + 5;
const int M = 2e5 + 5;
const int LG = 20;
const int INF = 1e9 + 5;
const int K = 2;
const int C = 26;
const int B = 1000;
const int MOD = 998244353;

long long n, k, a[N], pref[N];
long long ans, cur;

inline void solve()
{
    cin >> n >> k;
    ans = 0;
    cur = 0;
    for (int x = 1; x <= n; x++)
    {
        cin >> a[x];
        pref[x] = pref[x - 1] + a[x];
    }
    if ((n + 1) / 2 <= k)
    {
        for (int x = 1; x <= n; x++)
        {
            if (a[x] > 0)
                ans += a[x];
        }
        cout << ans << "\n";
        return;
    }
    sort(pref, pref + n + 1);
    for (int x = 0; x < k; x++)
    {
        cur += pref[n - x] - pref[x];
        ans = max(ans, cur);
    }
    cout << ans << "\n";
}

signed main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    int t = 1;
    // cin >> t;
    for (int x = 1; x <= t; x++)
    {
        solve();
    }
    return 0;
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...