#include<bits/stdc++.h>
#define int long long
using namespace std;
int n,k, arr[300300], l, r, vis[300300], mx = -1e18, sum, now, ans;
signed main(){
cin.tie(nullptr)->sync_with_stdio(false);
cin >> n >> k;
for(int i = 1; i<=n; ++i) cin >> arr[i];
for(int i = 1; i<=k; ++i){
mx = -1e18;
int cnt = 0, now = 0, sum = 0;
for(int j = 1; j<=n; ++j){
if(vis[j]){
sum = 0;
cnt = 0;
continue;
}
sum+=arr[j];
cnt++;
if(mx < sum){
mx = sum;
now = cnt;
r = j;
}
if(sum < 0){
sum = 0;
cnt = 0;
}
}
if(mx > 0) for(int j = r - now + 1; j<=r; ++j) vis[j] = 1;
ans+=max(0ll, mx);
}
cout << ans;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Execution timed out |
1034 ms |
4952 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
15 ms |
4952 KB |
Output is correct |
2 |
Correct |
16 ms |
4944 KB |
Output is correct |
3 |
Correct |
16 ms |
4816 KB |
Output is correct |
4 |
Execution timed out |
1002 ms |
4952 KB |
Time limit exceeded |
5 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
24 ms |
2908 KB |
Output is correct |
2 |
Correct |
24 ms |
2648 KB |
Output is correct |
3 |
Correct |
25 ms |
2648 KB |
Output is correct |
4 |
Correct |
24 ms |
2652 KB |
Output is correct |
5 |
Correct |
26 ms |
3152 KB |
Output is correct |
6 |
Correct |
25 ms |
2652 KB |
Output is correct |
7 |
Correct |
25 ms |
2908 KB |
Output is correct |
8 |
Correct |
24 ms |
2772 KB |
Output is correct |
9 |
Correct |
24 ms |
2904 KB |
Output is correct |
10 |
Correct |
25 ms |
2908 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
2392 KB |
Output is correct |
2 |
Incorrect |
1 ms |
2392 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
2392 KB |
Output is correct |
2 |
Incorrect |
1 ms |
2392 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
2392 KB |
Output is correct |
2 |
Incorrect |
1 ms |
2392 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Execution timed out |
1034 ms |
4952 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |