#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef long double ld;
#define pb push_back
#define pf push_front
#define fi first
#define se second
const ll mod = 1e9+7, mxn = 3e5+7;
ll n, a[mxn], k;
pair<ll,ll> lmb(ll x)
{
pair<ll,ll> dp[mxn][2];
dp[1][0] = {0,0}; dp[1][1] = {a[1]-x,1};
for (ll i = 2; i <= n; i++)
{
dp[i][0] = max(dp[i-1][0],dp[i-1][1]);
dp[i][1] = max(make_pair(dp[i-1][0].fi+a[i]-x,dp[i-1][0].se+1),
make_pair(dp[i-1][1].fi+a[i],dp[i-1][1].se));
}
return max(dp[n][0],dp[n][1]);
}
void aliens()
{
ll l = 0, r = 1e18, ans = -1;
while (r >= l)
{
ll m = (r+l)>>1;
pair<ll,ll> opt = lmb(m);
if (opt.se <= k)
{
ans = max(ans,opt.fi+m*opt.se);
r = m-1;
}
else l = m+1;
}
cout << ans;
}
signed main()
{
ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
// freopen("test.inp","r",stdin); freopen("test.out","w",stdout); freopen("test.err","w",stderr);
cin >> n >> k;
for (ll i = 1; i <= n; i++) cin >> a[i];
aliens();
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
69 ms |
11868 KB |
Output is correct |
2 |
Correct |
70 ms |
12112 KB |
Output is correct |
3 |
Correct |
71 ms |
12120 KB |
Output is correct |
4 |
Correct |
71 ms |
12116 KB |
Output is correct |
5 |
Correct |
71 ms |
12112 KB |
Output is correct |
6 |
Correct |
70 ms |
12100 KB |
Output is correct |
7 |
Correct |
69 ms |
11864 KB |
Output is correct |
8 |
Correct |
72 ms |
12112 KB |
Output is correct |
9 |
Correct |
68 ms |
11860 KB |
Output is correct |
10 |
Correct |
77 ms |
12136 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
62 ms |
12124 KB |
Output is correct |
2 |
Correct |
64 ms |
12168 KB |
Output is correct |
3 |
Correct |
62 ms |
12120 KB |
Output is correct |
4 |
Correct |
62 ms |
12124 KB |
Output is correct |
5 |
Correct |
70 ms |
11856 KB |
Output is correct |
6 |
Correct |
64 ms |
12120 KB |
Output is correct |
7 |
Correct |
66 ms |
12112 KB |
Output is correct |
8 |
Correct |
72 ms |
12124 KB |
Output is correct |
9 |
Correct |
70 ms |
12104 KB |
Output is correct |
10 |
Correct |
64 ms |
12164 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
99 ms |
12148 KB |
Output is correct |
2 |
Correct |
109 ms |
12116 KB |
Output is correct |
3 |
Correct |
96 ms |
12112 KB |
Output is correct |
4 |
Correct |
124 ms |
12120 KB |
Output is correct |
5 |
Correct |
104 ms |
12120 KB |
Output is correct |
6 |
Correct |
98 ms |
12116 KB |
Output is correct |
7 |
Correct |
97 ms |
12112 KB |
Output is correct |
8 |
Correct |
97 ms |
12124 KB |
Output is correct |
9 |
Correct |
105 ms |
12168 KB |
Output is correct |
10 |
Correct |
97 ms |
12124 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
18 ms |
9820 KB |
Output is correct |
2 |
Correct |
19 ms |
9820 KB |
Output is correct |
3 |
Correct |
20 ms |
9816 KB |
Output is correct |
4 |
Correct |
18 ms |
9820 KB |
Output is correct |
5 |
Correct |
18 ms |
9820 KB |
Output is correct |
6 |
Correct |
18 ms |
9776 KB |
Output is correct |
7 |
Correct |
18 ms |
9852 KB |
Output is correct |
8 |
Correct |
18 ms |
9624 KB |
Output is correct |
9 |
Correct |
20 ms |
9848 KB |
Output is correct |
10 |
Correct |
18 ms |
9816 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
18 ms |
9820 KB |
Output is correct |
2 |
Correct |
19 ms |
9820 KB |
Output is correct |
3 |
Correct |
20 ms |
9816 KB |
Output is correct |
4 |
Correct |
18 ms |
9820 KB |
Output is correct |
5 |
Correct |
18 ms |
9820 KB |
Output is correct |
6 |
Correct |
18 ms |
9776 KB |
Output is correct |
7 |
Correct |
18 ms |
9852 KB |
Output is correct |
8 |
Correct |
18 ms |
9624 KB |
Output is correct |
9 |
Correct |
20 ms |
9848 KB |
Output is correct |
10 |
Correct |
18 ms |
9816 KB |
Output is correct |
11 |
Correct |
18 ms |
9816 KB |
Output is correct |
12 |
Correct |
19 ms |
9820 KB |
Output is correct |
13 |
Correct |
18 ms |
9820 KB |
Output is correct |
14 |
Correct |
20 ms |
9732 KB |
Output is correct |
15 |
Correct |
20 ms |
9816 KB |
Output is correct |
16 |
Correct |
18 ms |
9820 KB |
Output is correct |
17 |
Correct |
19 ms |
9820 KB |
Output is correct |
18 |
Correct |
19 ms |
9820 KB |
Output is correct |
19 |
Correct |
19 ms |
9820 KB |
Output is correct |
20 |
Correct |
19 ms |
9648 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
18 ms |
9820 KB |
Output is correct |
2 |
Correct |
19 ms |
9820 KB |
Output is correct |
3 |
Correct |
20 ms |
9816 KB |
Output is correct |
4 |
Correct |
18 ms |
9820 KB |
Output is correct |
5 |
Correct |
18 ms |
9820 KB |
Output is correct |
6 |
Correct |
18 ms |
9776 KB |
Output is correct |
7 |
Correct |
18 ms |
9852 KB |
Output is correct |
8 |
Correct |
18 ms |
9624 KB |
Output is correct |
9 |
Correct |
20 ms |
9848 KB |
Output is correct |
10 |
Correct |
18 ms |
9816 KB |
Output is correct |
11 |
Correct |
18 ms |
9816 KB |
Output is correct |
12 |
Correct |
19 ms |
9820 KB |
Output is correct |
13 |
Correct |
18 ms |
9820 KB |
Output is correct |
14 |
Correct |
20 ms |
9732 KB |
Output is correct |
15 |
Correct |
20 ms |
9816 KB |
Output is correct |
16 |
Correct |
18 ms |
9820 KB |
Output is correct |
17 |
Correct |
19 ms |
9820 KB |
Output is correct |
18 |
Correct |
19 ms |
9820 KB |
Output is correct |
19 |
Correct |
19 ms |
9820 KB |
Output is correct |
20 |
Correct |
19 ms |
9648 KB |
Output is correct |
21 |
Correct |
19 ms |
9820 KB |
Output is correct |
22 |
Correct |
20 ms |
9816 KB |
Output is correct |
23 |
Correct |
18 ms |
9820 KB |
Output is correct |
24 |
Correct |
19 ms |
9816 KB |
Output is correct |
25 |
Correct |
18 ms |
9820 KB |
Output is correct |
26 |
Correct |
20 ms |
9864 KB |
Output is correct |
27 |
Correct |
20 ms |
9872 KB |
Output is correct |
28 |
Correct |
18 ms |
9816 KB |
Output is correct |
29 |
Correct |
19 ms |
9816 KB |
Output is correct |
30 |
Correct |
22 ms |
9820 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
69 ms |
11868 KB |
Output is correct |
2 |
Correct |
70 ms |
12112 KB |
Output is correct |
3 |
Correct |
71 ms |
12120 KB |
Output is correct |
4 |
Correct |
71 ms |
12116 KB |
Output is correct |
5 |
Correct |
71 ms |
12112 KB |
Output is correct |
6 |
Correct |
70 ms |
12100 KB |
Output is correct |
7 |
Correct |
69 ms |
11864 KB |
Output is correct |
8 |
Correct |
72 ms |
12112 KB |
Output is correct |
9 |
Correct |
68 ms |
11860 KB |
Output is correct |
10 |
Correct |
77 ms |
12136 KB |
Output is correct |
11 |
Correct |
62 ms |
12124 KB |
Output is correct |
12 |
Correct |
64 ms |
12168 KB |
Output is correct |
13 |
Correct |
62 ms |
12120 KB |
Output is correct |
14 |
Correct |
62 ms |
12124 KB |
Output is correct |
15 |
Correct |
70 ms |
11856 KB |
Output is correct |
16 |
Correct |
64 ms |
12120 KB |
Output is correct |
17 |
Correct |
66 ms |
12112 KB |
Output is correct |
18 |
Correct |
72 ms |
12124 KB |
Output is correct |
19 |
Correct |
70 ms |
12104 KB |
Output is correct |
20 |
Correct |
64 ms |
12164 KB |
Output is correct |
21 |
Correct |
99 ms |
12148 KB |
Output is correct |
22 |
Correct |
109 ms |
12116 KB |
Output is correct |
23 |
Correct |
96 ms |
12112 KB |
Output is correct |
24 |
Correct |
124 ms |
12120 KB |
Output is correct |
25 |
Correct |
104 ms |
12120 KB |
Output is correct |
26 |
Correct |
98 ms |
12116 KB |
Output is correct |
27 |
Correct |
97 ms |
12112 KB |
Output is correct |
28 |
Correct |
97 ms |
12124 KB |
Output is correct |
29 |
Correct |
105 ms |
12168 KB |
Output is correct |
30 |
Correct |
97 ms |
12124 KB |
Output is correct |
31 |
Correct |
18 ms |
9820 KB |
Output is correct |
32 |
Correct |
19 ms |
9820 KB |
Output is correct |
33 |
Correct |
20 ms |
9816 KB |
Output is correct |
34 |
Correct |
18 ms |
9820 KB |
Output is correct |
35 |
Correct |
18 ms |
9820 KB |
Output is correct |
36 |
Correct |
18 ms |
9776 KB |
Output is correct |
37 |
Correct |
18 ms |
9852 KB |
Output is correct |
38 |
Correct |
18 ms |
9624 KB |
Output is correct |
39 |
Correct |
20 ms |
9848 KB |
Output is correct |
40 |
Correct |
18 ms |
9816 KB |
Output is correct |
41 |
Correct |
18 ms |
9816 KB |
Output is correct |
42 |
Correct |
19 ms |
9820 KB |
Output is correct |
43 |
Correct |
18 ms |
9820 KB |
Output is correct |
44 |
Correct |
20 ms |
9732 KB |
Output is correct |
45 |
Correct |
20 ms |
9816 KB |
Output is correct |
46 |
Correct |
18 ms |
9820 KB |
Output is correct |
47 |
Correct |
19 ms |
9820 KB |
Output is correct |
48 |
Correct |
19 ms |
9820 KB |
Output is correct |
49 |
Correct |
19 ms |
9820 KB |
Output is correct |
50 |
Correct |
19 ms |
9648 KB |
Output is correct |
51 |
Correct |
19 ms |
9820 KB |
Output is correct |
52 |
Correct |
20 ms |
9816 KB |
Output is correct |
53 |
Correct |
18 ms |
9820 KB |
Output is correct |
54 |
Correct |
19 ms |
9816 KB |
Output is correct |
55 |
Correct |
18 ms |
9820 KB |
Output is correct |
56 |
Correct |
20 ms |
9864 KB |
Output is correct |
57 |
Correct |
20 ms |
9872 KB |
Output is correct |
58 |
Correct |
18 ms |
9816 KB |
Output is correct |
59 |
Correct |
19 ms |
9816 KB |
Output is correct |
60 |
Correct |
22 ms |
9820 KB |
Output is correct |
61 |
Correct |
123 ms |
12124 KB |
Output is correct |
62 |
Correct |
114 ms |
12120 KB |
Output is correct |
63 |
Correct |
110 ms |
11860 KB |
Output is correct |
64 |
Correct |
154 ms |
12160 KB |
Output is correct |
65 |
Correct |
132 ms |
12124 KB |
Output is correct |
66 |
Correct |
131 ms |
12364 KB |
Output is correct |
67 |
Correct |
134 ms |
12116 KB |
Output is correct |
68 |
Correct |
99 ms |
12124 KB |
Output is correct |
69 |
Correct |
96 ms |
12112 KB |
Output is correct |
70 |
Correct |
95 ms |
11860 KB |
Output is correct |