# | TimeUTC-0 | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
833141 | veehz | Feast (NOI19_feast) | C++17 | 255 ms | 262144 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
#define pb push_back
int main() {
int n, k;
cin >> n >> k;
vector<ll> a(n);
for (int i = 0; i < n; i++) cin >> a[i];
// subtask 1 a_i > 0
if (*min_element(a.begin(), a.end()) >= 0) {
cout << accumulate(a.begin(), a.end(), 0LL) << endl;
return 0;
}
// subtask 2 at most one a_i < 0
if (count_if(a.begin(), a.end(), [](ll x) { return x < 0; }) <= 1) {
int pos =
find_if(a.begin(), a.end(), [](ll x) { return x < 0; }) - a.begin();
ll mx = 0;
mx = max(mx, accumulate(a.begin(), a.begin() + pos, 0LL));
mx = max(mx, accumulate(a.begin() + pos + 1, a.end(), 0LL));
mx = max(mx, accumulate(a.begin(), a.end(), 0LL));
if (k >= 2) mx = max(mx, accumulate(a.begin(), a.end(), 0LL) - a[pos]);
cout << mx << endl;
return 0;
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |