#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
#define F first
#define S second
#define pb push_back
#define sz(a) (int)a.size()
#define all(x) (x).begin(), (x).end()
int n, k;
vector<ll> a = {0};
void f() {
ll ans = 0, nw = 0;
for (auto& u : a) {
nw = max(0LL, nw + u);
ans = max(ans, nw);
}
cout << ans << endl;
return;
}
int main() {
cin >> n >> k;
vector<ll> v;
for (int i = 0; i < n; i++) {
ll x;
cin >> x;
a.pb(x);
}
if (k == 1) {
f();
return 0;
}
ll cnt = 0;
for (auto& u : a)
if (u > 0) cnt += u;
cout << cnt << endl;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
81 ms |
4816 KB |
Output is correct |
2 |
Correct |
84 ms |
4752 KB |
Output is correct |
3 |
Correct |
92 ms |
4904 KB |
Output is correct |
4 |
Correct |
97 ms |
4772 KB |
Output is correct |
5 |
Correct |
83 ms |
4760 KB |
Output is correct |
6 |
Correct |
81 ms |
4792 KB |
Output is correct |
7 |
Correct |
81 ms |
4664 KB |
Output is correct |
8 |
Correct |
90 ms |
4888 KB |
Output is correct |
9 |
Correct |
81 ms |
4712 KB |
Output is correct |
10 |
Correct |
82 ms |
4740 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
50 ms |
4724 KB |
Output is correct |
2 |
Correct |
46 ms |
4724 KB |
Output is correct |
3 |
Correct |
45 ms |
4744 KB |
Output is correct |
4 |
Correct |
60 ms |
4784 KB |
Output is correct |
5 |
Correct |
81 ms |
4752 KB |
Output is correct |
6 |
Correct |
45 ms |
4652 KB |
Output is correct |
7 |
Correct |
46 ms |
4756 KB |
Output is correct |
8 |
Correct |
85 ms |
4664 KB |
Output is correct |
9 |
Correct |
87 ms |
4716 KB |
Output is correct |
10 |
Correct |
47 ms |
4688 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
91 ms |
4848 KB |
Output is correct |
2 |
Correct |
107 ms |
4828 KB |
Output is correct |
3 |
Correct |
89 ms |
4856 KB |
Output is correct |
4 |
Correct |
99 ms |
4948 KB |
Output is correct |
5 |
Correct |
88 ms |
4844 KB |
Output is correct |
6 |
Correct |
89 ms |
4792 KB |
Output is correct |
7 |
Correct |
91 ms |
4916 KB |
Output is correct |
8 |
Correct |
89 ms |
4820 KB |
Output is correct |
9 |
Correct |
96 ms |
4816 KB |
Output is correct |
10 |
Correct |
91 ms |
4604 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Incorrect |
0 ms |
212 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Incorrect |
0 ms |
212 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Incorrect |
0 ms |
212 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
81 ms |
4816 KB |
Output is correct |
2 |
Correct |
84 ms |
4752 KB |
Output is correct |
3 |
Correct |
92 ms |
4904 KB |
Output is correct |
4 |
Correct |
97 ms |
4772 KB |
Output is correct |
5 |
Correct |
83 ms |
4760 KB |
Output is correct |
6 |
Correct |
81 ms |
4792 KB |
Output is correct |
7 |
Correct |
81 ms |
4664 KB |
Output is correct |
8 |
Correct |
90 ms |
4888 KB |
Output is correct |
9 |
Correct |
81 ms |
4712 KB |
Output is correct |
10 |
Correct |
82 ms |
4740 KB |
Output is correct |
11 |
Correct |
50 ms |
4724 KB |
Output is correct |
12 |
Correct |
46 ms |
4724 KB |
Output is correct |
13 |
Correct |
45 ms |
4744 KB |
Output is correct |
14 |
Correct |
60 ms |
4784 KB |
Output is correct |
15 |
Correct |
81 ms |
4752 KB |
Output is correct |
16 |
Correct |
45 ms |
4652 KB |
Output is correct |
17 |
Correct |
46 ms |
4756 KB |
Output is correct |
18 |
Correct |
85 ms |
4664 KB |
Output is correct |
19 |
Correct |
87 ms |
4716 KB |
Output is correct |
20 |
Correct |
47 ms |
4688 KB |
Output is correct |
21 |
Correct |
91 ms |
4848 KB |
Output is correct |
22 |
Correct |
107 ms |
4828 KB |
Output is correct |
23 |
Correct |
89 ms |
4856 KB |
Output is correct |
24 |
Correct |
99 ms |
4948 KB |
Output is correct |
25 |
Correct |
88 ms |
4844 KB |
Output is correct |
26 |
Correct |
89 ms |
4792 KB |
Output is correct |
27 |
Correct |
91 ms |
4916 KB |
Output is correct |
28 |
Correct |
89 ms |
4820 KB |
Output is correct |
29 |
Correct |
96 ms |
4816 KB |
Output is correct |
30 |
Correct |
91 ms |
4604 KB |
Output is correct |
31 |
Correct |
0 ms |
212 KB |
Output is correct |
32 |
Correct |
0 ms |
212 KB |
Output is correct |
33 |
Incorrect |
0 ms |
212 KB |
Output isn't correct |
34 |
Halted |
0 ms |
0 KB |
- |