/*==============================================================================================================
__ __ _____ ______ _______
| | | | / __ \ / _____| / ______|
__| |__ __| |__ |_| | | | | | |
|__| __| |__| __| | | | |____ | |_____
| | _____ _ | | ____ __ __ ____ _____ _____ / / \ ___ \ | ___ \
| | / _ \ | | | | / _/ | | | | / _ \ / __ \ / _ \ / / | | | | | |
| |_ | |_| | | | | |_ | | | |_| | | |_| | | | | | | |_| | / /___ ____| | | |___| |
\____\ \____/| |_| \____\ |_| \_____/ \_____/ |_| |_| \____ | |______| |______/ \_______/
| |
__/ |
|___/
Pratice, practice, and practice
Where is the bug, delete it there
Try, try, try again until you succeed
I hated every minute of training, but I said, 'Don't quit. Suffer now and live the rest of your life as a champion.' - Mohamed Ali
You may not be the best, but must be the most effort
Even the things and people you like, you don't have the courage to take, you are destined to be a failure.
Difficult means more time
Done is better than perfect
Pain + Reflection = Progress
==============================================================================================================*/
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ld long double
#define endl '\n'
const ll mod = 1e9+7;
ll n, k, a[300005];
pair<ld, ll> dp[300005][3]; //sum doan, cnt doan
ld l, r, lambda;
bool check(ld m)
{
dp[0][0]={0, 0};
dp[0][1]={-1e18, 0};
for (ll i=1; i<=n; i++)
{
dp[i][0]=max(dp[i-1][0], dp[i-1][1]);
dp[i][1]=max( make_pair(dp[i-1][1].first+a[i], dp[i-1][1].second), //them a[i] vao doan truoc do
make_pair(dp[i-1][0].first+a[i]-m, dp[i-1][0].second+1)); // bat dau doan moi tai vi tri a[i]
}
return max(dp[n][0], dp[n][1]).second>=k;
}
void solve()
{
cin>>n>>k;
for (ll i=1; i<=n; i++) cin>>a[i];
l=0, r=1e18;
ld eps=1e-3;
while (r-l>eps)
{
ld mid=(l+r)/2;
if (check(mid)==true) l=mid;
else r=mid;
}
lambda=l;
check(lambda);
cout<<llround(max(dp[n][0], dp[n][1]).first+lambda*k);
}
int main()
{
ios_base::sync_with_stdio(false); cin.tie(NULL);
clock_t start = clock();
//#ifndef ONLINE_JUDGE
//freopen("_input.txt", "r", stdin);
//freopen("_output.txt", "w", stdout);
//#endif
solve();
clock_t end = clock();
cerr<<"Time: "<<fixed<<setprecision(10)<<double(end-start)/double(CLOCKS_PER_SEC)<<"\n";
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
226 ms |
30800 KB |
Output is correct |
2 |
Correct |
228 ms |
30940 KB |
Output is correct |
3 |
Correct |
236 ms |
30972 KB |
Output is correct |
4 |
Correct |
230 ms |
30800 KB |
Output is correct |
5 |
Correct |
228 ms |
30932 KB |
Output is correct |
6 |
Correct |
223 ms |
30892 KB |
Output is correct |
7 |
Correct |
224 ms |
30892 KB |
Output is correct |
8 |
Correct |
225 ms |
30704 KB |
Output is correct |
9 |
Correct |
226 ms |
30808 KB |
Output is correct |
10 |
Correct |
222 ms |
30800 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
228 ms |
30908 KB |
Output is correct |
2 |
Correct |
246 ms |
30964 KB |
Output is correct |
3 |
Correct |
220 ms |
31064 KB |
Output is correct |
4 |
Correct |
229 ms |
30924 KB |
Output is correct |
5 |
Correct |
227 ms |
30800 KB |
Output is correct |
6 |
Correct |
222 ms |
32028 KB |
Output is correct |
7 |
Correct |
230 ms |
32336 KB |
Output is correct |
8 |
Correct |
233 ms |
33620 KB |
Output is correct |
9 |
Correct |
228 ms |
33616 KB |
Output is correct |
10 |
Correct |
223 ms |
32080 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
272 ms |
31160 KB |
Output is correct |
2 |
Correct |
271 ms |
31068 KB |
Output is correct |
3 |
Correct |
279 ms |
30936 KB |
Output is correct |
4 |
Correct |
271 ms |
30908 KB |
Output is correct |
5 |
Correct |
272 ms |
30940 KB |
Output is correct |
6 |
Correct |
276 ms |
31172 KB |
Output is correct |
7 |
Correct |
275 ms |
30960 KB |
Output is correct |
8 |
Correct |
268 ms |
30800 KB |
Output is correct |
9 |
Correct |
278 ms |
31060 KB |
Output is correct |
10 |
Correct |
271 ms |
30884 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
2392 KB |
Output is correct |
2 |
Correct |
1 ms |
2396 KB |
Output is correct |
3 |
Correct |
1 ms |
2396 KB |
Output is correct |
4 |
Correct |
1 ms |
2392 KB |
Output is correct |
5 |
Correct |
1 ms |
2396 KB |
Output is correct |
6 |
Correct |
1 ms |
2396 KB |
Output is correct |
7 |
Correct |
1 ms |
2396 KB |
Output is correct |
8 |
Correct |
1 ms |
2396 KB |
Output is correct |
9 |
Correct |
1 ms |
2392 KB |
Output is correct |
10 |
Correct |
1 ms |
2392 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
2392 KB |
Output is correct |
2 |
Correct |
1 ms |
2396 KB |
Output is correct |
3 |
Correct |
1 ms |
2396 KB |
Output is correct |
4 |
Correct |
1 ms |
2392 KB |
Output is correct |
5 |
Correct |
1 ms |
2396 KB |
Output is correct |
6 |
Correct |
1 ms |
2396 KB |
Output is correct |
7 |
Correct |
1 ms |
2396 KB |
Output is correct |
8 |
Correct |
1 ms |
2396 KB |
Output is correct |
9 |
Correct |
1 ms |
2392 KB |
Output is correct |
10 |
Correct |
1 ms |
2392 KB |
Output is correct |
11 |
Correct |
1 ms |
2396 KB |
Output is correct |
12 |
Correct |
1 ms |
2396 KB |
Output is correct |
13 |
Correct |
1 ms |
2396 KB |
Output is correct |
14 |
Correct |
1 ms |
2544 KB |
Output is correct |
15 |
Correct |
1 ms |
2396 KB |
Output is correct |
16 |
Correct |
1 ms |
2396 KB |
Output is correct |
17 |
Correct |
1 ms |
2396 KB |
Output is correct |
18 |
Correct |
1 ms |
2396 KB |
Output is correct |
19 |
Correct |
1 ms |
2404 KB |
Output is correct |
20 |
Correct |
1 ms |
2396 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
2392 KB |
Output is correct |
2 |
Correct |
1 ms |
2396 KB |
Output is correct |
3 |
Correct |
1 ms |
2396 KB |
Output is correct |
4 |
Correct |
1 ms |
2392 KB |
Output is correct |
5 |
Correct |
1 ms |
2396 KB |
Output is correct |
6 |
Correct |
1 ms |
2396 KB |
Output is correct |
7 |
Correct |
1 ms |
2396 KB |
Output is correct |
8 |
Correct |
1 ms |
2396 KB |
Output is correct |
9 |
Correct |
1 ms |
2392 KB |
Output is correct |
10 |
Correct |
1 ms |
2392 KB |
Output is correct |
11 |
Correct |
1 ms |
2396 KB |
Output is correct |
12 |
Correct |
1 ms |
2396 KB |
Output is correct |
13 |
Correct |
1 ms |
2396 KB |
Output is correct |
14 |
Correct |
1 ms |
2544 KB |
Output is correct |
15 |
Correct |
1 ms |
2396 KB |
Output is correct |
16 |
Correct |
1 ms |
2396 KB |
Output is correct |
17 |
Correct |
1 ms |
2396 KB |
Output is correct |
18 |
Correct |
1 ms |
2396 KB |
Output is correct |
19 |
Correct |
1 ms |
2404 KB |
Output is correct |
20 |
Correct |
1 ms |
2396 KB |
Output is correct |
21 |
Correct |
3 ms |
2652 KB |
Output is correct |
22 |
Correct |
2 ms |
2652 KB |
Output is correct |
23 |
Correct |
3 ms |
4700 KB |
Output is correct |
24 |
Correct |
2 ms |
2648 KB |
Output is correct |
25 |
Correct |
2 ms |
4700 KB |
Output is correct |
26 |
Correct |
3 ms |
4700 KB |
Output is correct |
27 |
Correct |
3 ms |
4700 KB |
Output is correct |
28 |
Correct |
3 ms |
4700 KB |
Output is correct |
29 |
Correct |
3 ms |
4696 KB |
Output is correct |
30 |
Correct |
2 ms |
2464 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
226 ms |
30800 KB |
Output is correct |
2 |
Correct |
228 ms |
30940 KB |
Output is correct |
3 |
Correct |
236 ms |
30972 KB |
Output is correct |
4 |
Correct |
230 ms |
30800 KB |
Output is correct |
5 |
Correct |
228 ms |
30932 KB |
Output is correct |
6 |
Correct |
223 ms |
30892 KB |
Output is correct |
7 |
Correct |
224 ms |
30892 KB |
Output is correct |
8 |
Correct |
225 ms |
30704 KB |
Output is correct |
9 |
Correct |
226 ms |
30808 KB |
Output is correct |
10 |
Correct |
222 ms |
30800 KB |
Output is correct |
11 |
Correct |
228 ms |
30908 KB |
Output is correct |
12 |
Correct |
246 ms |
30964 KB |
Output is correct |
13 |
Correct |
220 ms |
31064 KB |
Output is correct |
14 |
Correct |
229 ms |
30924 KB |
Output is correct |
15 |
Correct |
227 ms |
30800 KB |
Output is correct |
16 |
Correct |
222 ms |
32028 KB |
Output is correct |
17 |
Correct |
230 ms |
32336 KB |
Output is correct |
18 |
Correct |
233 ms |
33620 KB |
Output is correct |
19 |
Correct |
228 ms |
33616 KB |
Output is correct |
20 |
Correct |
223 ms |
32080 KB |
Output is correct |
21 |
Correct |
272 ms |
31160 KB |
Output is correct |
22 |
Correct |
271 ms |
31068 KB |
Output is correct |
23 |
Correct |
279 ms |
30936 KB |
Output is correct |
24 |
Correct |
271 ms |
30908 KB |
Output is correct |
25 |
Correct |
272 ms |
30940 KB |
Output is correct |
26 |
Correct |
276 ms |
31172 KB |
Output is correct |
27 |
Correct |
275 ms |
30960 KB |
Output is correct |
28 |
Correct |
268 ms |
30800 KB |
Output is correct |
29 |
Correct |
278 ms |
31060 KB |
Output is correct |
30 |
Correct |
271 ms |
30884 KB |
Output is correct |
31 |
Correct |
1 ms |
2392 KB |
Output is correct |
32 |
Correct |
1 ms |
2396 KB |
Output is correct |
33 |
Correct |
1 ms |
2396 KB |
Output is correct |
34 |
Correct |
1 ms |
2392 KB |
Output is correct |
35 |
Correct |
1 ms |
2396 KB |
Output is correct |
36 |
Correct |
1 ms |
2396 KB |
Output is correct |
37 |
Correct |
1 ms |
2396 KB |
Output is correct |
38 |
Correct |
1 ms |
2396 KB |
Output is correct |
39 |
Correct |
1 ms |
2392 KB |
Output is correct |
40 |
Correct |
1 ms |
2392 KB |
Output is correct |
41 |
Correct |
1 ms |
2396 KB |
Output is correct |
42 |
Correct |
1 ms |
2396 KB |
Output is correct |
43 |
Correct |
1 ms |
2396 KB |
Output is correct |
44 |
Correct |
1 ms |
2544 KB |
Output is correct |
45 |
Correct |
1 ms |
2396 KB |
Output is correct |
46 |
Correct |
1 ms |
2396 KB |
Output is correct |
47 |
Correct |
1 ms |
2396 KB |
Output is correct |
48 |
Correct |
1 ms |
2396 KB |
Output is correct |
49 |
Correct |
1 ms |
2404 KB |
Output is correct |
50 |
Correct |
1 ms |
2396 KB |
Output is correct |
51 |
Correct |
3 ms |
2652 KB |
Output is correct |
52 |
Correct |
2 ms |
2652 KB |
Output is correct |
53 |
Correct |
3 ms |
4700 KB |
Output is correct |
54 |
Correct |
2 ms |
2648 KB |
Output is correct |
55 |
Correct |
2 ms |
4700 KB |
Output is correct |
56 |
Correct |
3 ms |
4700 KB |
Output is correct |
57 |
Correct |
3 ms |
4700 KB |
Output is correct |
58 |
Correct |
3 ms |
4700 KB |
Output is correct |
59 |
Correct |
3 ms |
4696 KB |
Output is correct |
60 |
Correct |
2 ms |
2464 KB |
Output is correct |
61 |
Correct |
337 ms |
33892 KB |
Output is correct |
62 |
Correct |
340 ms |
34032 KB |
Output is correct |
63 |
Correct |
295 ms |
34132 KB |
Output is correct |
64 |
Correct |
342 ms |
33984 KB |
Output is correct |
65 |
Correct |
359 ms |
34128 KB |
Output is correct |
66 |
Correct |
344 ms |
33972 KB |
Output is correct |
67 |
Correct |
346 ms |
33888 KB |
Output is correct |
68 |
Correct |
277 ms |
33964 KB |
Output is correct |
69 |
Correct |
270 ms |
34096 KB |
Output is correct |
70 |
Correct |
267 ms |
33760 KB |
Output is correct |