#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define pii pair<int, int>
#define pll pair<ll, ll>
#define ff first
#define ss second
#define pb push_back
#define SZ(x) ((int)(x).size())
#define all(x) x.begin(), x.end()
#define debug(x) cout << #x << ": " << x << " "
#define nl cout << "\n"
#define rep(i, a, b) for(int i = (a); i < (b); i++)
#define per(i, a, b) for(int i = (a); i >= (b); i--)
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
const int MAXN = 3e5+100;
int N, K, a[MAXN];
ll dp[MAXN];
void solve(){
cin >> N >> K;
int cnt = 0;
rep(i, 1, N + 1){
cin >> a[i];
if(a[i] < 0) cnt++;
}
if(cnt <= 1) K = min(K, 2);
rep(k, 1, K + 1){
ll s = 0, mx = 0;
rep(i, 1, N + 1){
s += a[i];
s = max(s, dp[i]);
mx = max(mx, s);
dp[i] = mx;
}
}
cout << dp[N];
}
int main(){
ios_base::sync_with_stdio(false), cin.tie(nullptr);
solve();
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
35 ms |
3652 KB |
Output is correct |
2 |
Correct |
38 ms |
6524 KB |
Output is correct |
3 |
Correct |
38 ms |
6676 KB |
Output is correct |
4 |
Correct |
37 ms |
6596 KB |
Output is correct |
5 |
Correct |
42 ms |
6604 KB |
Output is correct |
6 |
Correct |
46 ms |
6528 KB |
Output is correct |
7 |
Correct |
37 ms |
6444 KB |
Output is correct |
8 |
Correct |
49 ms |
6656 KB |
Output is correct |
9 |
Correct |
36 ms |
6476 KB |
Output is correct |
10 |
Correct |
39 ms |
6596 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
30 ms |
3676 KB |
Output is correct |
2 |
Correct |
31 ms |
3780 KB |
Output is correct |
3 |
Correct |
24 ms |
3696 KB |
Output is correct |
4 |
Correct |
25 ms |
3788 KB |
Output is correct |
5 |
Correct |
48 ms |
6512 KB |
Output is correct |
6 |
Correct |
26 ms |
4788 KB |
Output is correct |
7 |
Correct |
26 ms |
4988 KB |
Output is correct |
8 |
Correct |
41 ms |
6676 KB |
Output is correct |
9 |
Correct |
37 ms |
6460 KB |
Output is correct |
10 |
Correct |
32 ms |
4916 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
39 ms |
3676 KB |
Output is correct |
2 |
Correct |
38 ms |
3644 KB |
Output is correct |
3 |
Correct |
39 ms |
3680 KB |
Output is correct |
4 |
Correct |
38 ms |
3688 KB |
Output is correct |
5 |
Correct |
40 ms |
3724 KB |
Output is correct |
6 |
Correct |
41 ms |
3716 KB |
Output is correct |
7 |
Correct |
46 ms |
3696 KB |
Output is correct |
8 |
Correct |
42 ms |
3728 KB |
Output is correct |
9 |
Correct |
40 ms |
3780 KB |
Output is correct |
10 |
Correct |
48 ms |
3816 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
332 KB |
Output is correct |
2 |
Correct |
1 ms |
204 KB |
Output is correct |
3 |
Correct |
1 ms |
204 KB |
Output is correct |
4 |
Correct |
1 ms |
204 KB |
Output is correct |
5 |
Correct |
1 ms |
332 KB |
Output is correct |
6 |
Correct |
1 ms |
332 KB |
Output is correct |
7 |
Correct |
1 ms |
332 KB |
Output is correct |
8 |
Correct |
1 ms |
332 KB |
Output is correct |
9 |
Correct |
1 ms |
332 KB |
Output is correct |
10 |
Correct |
1 ms |
204 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
332 KB |
Output is correct |
2 |
Correct |
1 ms |
204 KB |
Output is correct |
3 |
Correct |
1 ms |
204 KB |
Output is correct |
4 |
Correct |
1 ms |
204 KB |
Output is correct |
5 |
Correct |
1 ms |
332 KB |
Output is correct |
6 |
Correct |
1 ms |
332 KB |
Output is correct |
7 |
Correct |
1 ms |
332 KB |
Output is correct |
8 |
Correct |
1 ms |
332 KB |
Output is correct |
9 |
Correct |
1 ms |
332 KB |
Output is correct |
10 |
Correct |
1 ms |
204 KB |
Output is correct |
11 |
Correct |
1 ms |
332 KB |
Output is correct |
12 |
Correct |
1 ms |
332 KB |
Output is correct |
13 |
Correct |
1 ms |
332 KB |
Output is correct |
14 |
Correct |
1 ms |
332 KB |
Output is correct |
15 |
Correct |
1 ms |
332 KB |
Output is correct |
16 |
Correct |
1 ms |
332 KB |
Output is correct |
17 |
Correct |
1 ms |
332 KB |
Output is correct |
18 |
Correct |
1 ms |
332 KB |
Output is correct |
19 |
Correct |
1 ms |
332 KB |
Output is correct |
20 |
Correct |
1 ms |
332 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
332 KB |
Output is correct |
2 |
Correct |
1 ms |
204 KB |
Output is correct |
3 |
Correct |
1 ms |
204 KB |
Output is correct |
4 |
Correct |
1 ms |
204 KB |
Output is correct |
5 |
Correct |
1 ms |
332 KB |
Output is correct |
6 |
Correct |
1 ms |
332 KB |
Output is correct |
7 |
Correct |
1 ms |
332 KB |
Output is correct |
8 |
Correct |
1 ms |
332 KB |
Output is correct |
9 |
Correct |
1 ms |
332 KB |
Output is correct |
10 |
Correct |
1 ms |
204 KB |
Output is correct |
11 |
Correct |
1 ms |
332 KB |
Output is correct |
12 |
Correct |
1 ms |
332 KB |
Output is correct |
13 |
Correct |
1 ms |
332 KB |
Output is correct |
14 |
Correct |
1 ms |
332 KB |
Output is correct |
15 |
Correct |
1 ms |
332 KB |
Output is correct |
16 |
Correct |
1 ms |
332 KB |
Output is correct |
17 |
Correct |
1 ms |
332 KB |
Output is correct |
18 |
Correct |
1 ms |
332 KB |
Output is correct |
19 |
Correct |
1 ms |
332 KB |
Output is correct |
20 |
Correct |
1 ms |
332 KB |
Output is correct |
21 |
Correct |
2 ms |
332 KB |
Output is correct |
22 |
Correct |
7 ms |
332 KB |
Output is correct |
23 |
Correct |
2 ms |
332 KB |
Output is correct |
24 |
Correct |
2 ms |
332 KB |
Output is correct |
25 |
Correct |
2 ms |
332 KB |
Output is correct |
26 |
Correct |
2 ms |
364 KB |
Output is correct |
27 |
Correct |
2 ms |
332 KB |
Output is correct |
28 |
Correct |
1 ms |
332 KB |
Output is correct |
29 |
Correct |
1 ms |
336 KB |
Output is correct |
30 |
Correct |
2 ms |
332 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
35 ms |
3652 KB |
Output is correct |
2 |
Correct |
38 ms |
6524 KB |
Output is correct |
3 |
Correct |
38 ms |
6676 KB |
Output is correct |
4 |
Correct |
37 ms |
6596 KB |
Output is correct |
5 |
Correct |
42 ms |
6604 KB |
Output is correct |
6 |
Correct |
46 ms |
6528 KB |
Output is correct |
7 |
Correct |
37 ms |
6444 KB |
Output is correct |
8 |
Correct |
49 ms |
6656 KB |
Output is correct |
9 |
Correct |
36 ms |
6476 KB |
Output is correct |
10 |
Correct |
39 ms |
6596 KB |
Output is correct |
11 |
Correct |
30 ms |
3676 KB |
Output is correct |
12 |
Correct |
31 ms |
3780 KB |
Output is correct |
13 |
Correct |
24 ms |
3696 KB |
Output is correct |
14 |
Correct |
25 ms |
3788 KB |
Output is correct |
15 |
Correct |
48 ms |
6512 KB |
Output is correct |
16 |
Correct |
26 ms |
4788 KB |
Output is correct |
17 |
Correct |
26 ms |
4988 KB |
Output is correct |
18 |
Correct |
41 ms |
6676 KB |
Output is correct |
19 |
Correct |
37 ms |
6460 KB |
Output is correct |
20 |
Correct |
32 ms |
4916 KB |
Output is correct |
21 |
Correct |
39 ms |
3676 KB |
Output is correct |
22 |
Correct |
38 ms |
3644 KB |
Output is correct |
23 |
Correct |
39 ms |
3680 KB |
Output is correct |
24 |
Correct |
38 ms |
3688 KB |
Output is correct |
25 |
Correct |
40 ms |
3724 KB |
Output is correct |
26 |
Correct |
41 ms |
3716 KB |
Output is correct |
27 |
Correct |
46 ms |
3696 KB |
Output is correct |
28 |
Correct |
42 ms |
3728 KB |
Output is correct |
29 |
Correct |
40 ms |
3780 KB |
Output is correct |
30 |
Correct |
48 ms |
3816 KB |
Output is correct |
31 |
Correct |
1 ms |
332 KB |
Output is correct |
32 |
Correct |
1 ms |
204 KB |
Output is correct |
33 |
Correct |
1 ms |
204 KB |
Output is correct |
34 |
Correct |
1 ms |
204 KB |
Output is correct |
35 |
Correct |
1 ms |
332 KB |
Output is correct |
36 |
Correct |
1 ms |
332 KB |
Output is correct |
37 |
Correct |
1 ms |
332 KB |
Output is correct |
38 |
Correct |
1 ms |
332 KB |
Output is correct |
39 |
Correct |
1 ms |
332 KB |
Output is correct |
40 |
Correct |
1 ms |
204 KB |
Output is correct |
41 |
Correct |
1 ms |
332 KB |
Output is correct |
42 |
Correct |
1 ms |
332 KB |
Output is correct |
43 |
Correct |
1 ms |
332 KB |
Output is correct |
44 |
Correct |
1 ms |
332 KB |
Output is correct |
45 |
Correct |
1 ms |
332 KB |
Output is correct |
46 |
Correct |
1 ms |
332 KB |
Output is correct |
47 |
Correct |
1 ms |
332 KB |
Output is correct |
48 |
Correct |
1 ms |
332 KB |
Output is correct |
49 |
Correct |
1 ms |
332 KB |
Output is correct |
50 |
Correct |
1 ms |
332 KB |
Output is correct |
51 |
Correct |
2 ms |
332 KB |
Output is correct |
52 |
Correct |
7 ms |
332 KB |
Output is correct |
53 |
Correct |
2 ms |
332 KB |
Output is correct |
54 |
Correct |
2 ms |
332 KB |
Output is correct |
55 |
Correct |
2 ms |
332 KB |
Output is correct |
56 |
Correct |
2 ms |
364 KB |
Output is correct |
57 |
Correct |
2 ms |
332 KB |
Output is correct |
58 |
Correct |
1 ms |
332 KB |
Output is correct |
59 |
Correct |
1 ms |
336 KB |
Output is correct |
60 |
Correct |
2 ms |
332 KB |
Output is correct |
61 |
Execution timed out |
1083 ms |
6616 KB |
Time limit exceeded |
62 |
Halted |
0 ms |
0 KB |
- |