#include <bits/stdc++.h>
using namespace std;
#define int long long
signed main()
{
int n,k;
cin >> n >> k;
vector<int> a(n+1);
int ans=0,cur=0,sum=0;
for(int i=1;i<=n;i++)
{
cin >> a[i];
if(a[i]>=0)
{
sum+=a[i];
}
cur+=a[i];
ans=max(ans,cur);
cur=max(cur,0LL);
}
cout << (k==1?ans:sum) << '\n';
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
102 ms |
2560 KB |
Output is correct |
2 |
Correct |
107 ms |
2612 KB |
Output is correct |
3 |
Correct |
104 ms |
2644 KB |
Output is correct |
4 |
Correct |
105 ms |
2620 KB |
Output is correct |
5 |
Correct |
103 ms |
2604 KB |
Output is correct |
6 |
Correct |
102 ms |
2572 KB |
Output is correct |
7 |
Correct |
100 ms |
2568 KB |
Output is correct |
8 |
Correct |
102 ms |
2616 KB |
Output is correct |
9 |
Correct |
105 ms |
2516 KB |
Output is correct |
10 |
Correct |
110 ms |
2516 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
63 ms |
2596 KB |
Output is correct |
2 |
Correct |
61 ms |
2644 KB |
Output is correct |
3 |
Correct |
54 ms |
2516 KB |
Output is correct |
4 |
Correct |
54 ms |
2596 KB |
Output is correct |
5 |
Correct |
101 ms |
2564 KB |
Output is correct |
6 |
Correct |
61 ms |
2576 KB |
Output is correct |
7 |
Correct |
59 ms |
2644 KB |
Output is correct |
8 |
Correct |
107 ms |
2624 KB |
Output is correct |
9 |
Correct |
102 ms |
2560 KB |
Output is correct |
10 |
Correct |
56 ms |
2620 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
121 ms |
2516 KB |
Output is correct |
2 |
Correct |
109 ms |
2580 KB |
Output is correct |
3 |
Correct |
109 ms |
2604 KB |
Output is correct |
4 |
Correct |
109 ms |
2580 KB |
Output is correct |
5 |
Correct |
112 ms |
2516 KB |
Output is correct |
6 |
Correct |
123 ms |
2616 KB |
Output is correct |
7 |
Correct |
109 ms |
2644 KB |
Output is correct |
8 |
Correct |
112 ms |
2516 KB |
Output is correct |
9 |
Correct |
118 ms |
2764 KB |
Output is correct |
10 |
Correct |
131 ms |
2644 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 |
1 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 |
1 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 |
1 ms |
212 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
102 ms |
2560 KB |
Output is correct |
2 |
Correct |
107 ms |
2612 KB |
Output is correct |
3 |
Correct |
104 ms |
2644 KB |
Output is correct |
4 |
Correct |
105 ms |
2620 KB |
Output is correct |
5 |
Correct |
103 ms |
2604 KB |
Output is correct |
6 |
Correct |
102 ms |
2572 KB |
Output is correct |
7 |
Correct |
100 ms |
2568 KB |
Output is correct |
8 |
Correct |
102 ms |
2616 KB |
Output is correct |
9 |
Correct |
105 ms |
2516 KB |
Output is correct |
10 |
Correct |
110 ms |
2516 KB |
Output is correct |
11 |
Correct |
63 ms |
2596 KB |
Output is correct |
12 |
Correct |
61 ms |
2644 KB |
Output is correct |
13 |
Correct |
54 ms |
2516 KB |
Output is correct |
14 |
Correct |
54 ms |
2596 KB |
Output is correct |
15 |
Correct |
101 ms |
2564 KB |
Output is correct |
16 |
Correct |
61 ms |
2576 KB |
Output is correct |
17 |
Correct |
59 ms |
2644 KB |
Output is correct |
18 |
Correct |
107 ms |
2624 KB |
Output is correct |
19 |
Correct |
102 ms |
2560 KB |
Output is correct |
20 |
Correct |
56 ms |
2620 KB |
Output is correct |
21 |
Correct |
121 ms |
2516 KB |
Output is correct |
22 |
Correct |
109 ms |
2580 KB |
Output is correct |
23 |
Correct |
109 ms |
2604 KB |
Output is correct |
24 |
Correct |
109 ms |
2580 KB |
Output is correct |
25 |
Correct |
112 ms |
2516 KB |
Output is correct |
26 |
Correct |
123 ms |
2616 KB |
Output is correct |
27 |
Correct |
109 ms |
2644 KB |
Output is correct |
28 |
Correct |
112 ms |
2516 KB |
Output is correct |
29 |
Correct |
118 ms |
2764 KB |
Output is correct |
30 |
Correct |
131 ms |
2644 KB |
Output is correct |
31 |
Correct |
0 ms |
212 KB |
Output is correct |
32 |
Correct |
0 ms |
212 KB |
Output is correct |
33 |
Incorrect |
1 ms |
212 KB |
Output isn't correct |
34 |
Halted |
0 ms |
0 KB |
- |