# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
1017445 |
2024-07-09T08:05:05 Z |
anHiep |
Feast (NOI19_feast) |
C++14 |
|
84 ms |
15076 KB |
#include<bits/stdc++.h>
#ifdef LOCAL
#include "D:\debug.h"
#else
#define cebug(...) "Orz_chUoNgnn_khanhtb_0x2ee08"
#endif
using namespace std;
#define int long long
#define fi first
#define se second
#define pb push_back
#define ll long long
#define ii pair<int, int>
#define vi vector<int>
#define vll vector<ll>
#define vii vector<ii>
#define cd complex<double>
const ll mod = 1e9 + 7;
const ll INF = 1e18L + 5;
const double PI = acos(-1);
const int block = 320;
const int N = 3e5;
int tc, tt = 1;
int n, k;
int a[N + 5];
ll dp[N + 5][2], cnt[N + 5][2];
void solve() {
cin>>n>>k;
for(int i=1; i<=n; i++) cin>>a[i];
int l = 0, r = 1e9;
ll ans = 0;
while(l <= r) {
int mid = (l + r)/2;
dp[1][0] = 0;
dp[1][1] = a[1] - mid;
cnt[1][0] = 0;
cnt[1][1] = 1;
for(int i=2; i<=n; i++) {
ll v1 = dp[i - 1][0] + a[i] - mid;
ll v2 = dp[i - 1][1] + a[i];
dp[i][1] = max(v1, v2);
if(v1 == v2) cnt[i][1] = max(cnt[i - 1][0] + 1, cnt[i - 1][1]);
else {
if(dp[i][1] == v1) cnt[i][1] = cnt[i - 1][0] + 1;
else cnt[i][1] = cnt[i - 1][1];
}
v1 = dp[i - 1][0];
v2 = dp[i - 1][1];
dp[i][0] = max(v1, v2);
if(v1 == v2) cnt[i][0] = max(cnt[i - 1][0], cnt[i - 1][1]);
else {
if(dp[i][0] == v1) cnt[i][0] = cnt[i - 1][0];
else cnt[i][0] = cnt[i - 1][1];
}
}
ll seg = (dp[n][0] > dp[n][1] ? cnt[n][0] : cnt[n][1]);
if(dp[n][0] == dp[n][1]) seg = max(cnt[n][0], cnt[n][1]);
if(seg > k) l = mid + 1;
else {
if(seg == k)
ans = max(ans, max(dp[n][0], dp[n][1]) + mid * seg);
r = mid - 1;
}
}
cout<<ans;
}
signed main() {
ios_base::sync_with_stdio(0);
cin.tie(0); cout.tie(0);
// freopen(".INP", "r", stdin);
// freopen(".OUT", "w", stdout);
for(tc=1; tc<=tt; tc++) solve();
cerr<<"\nTime elapsed: "<<1000.0*clock()/CLOCKS_PER_SEC<<" ms.\n";
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
38 ms |
14536 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
33 ms |
13008 KB |
Output is correct |
2 |
Correct |
33 ms |
13148 KB |
Output is correct |
3 |
Correct |
31 ms |
12884 KB |
Output is correct |
4 |
Incorrect |
30 ms |
12892 KB |
Output isn't correct |
5 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
84 ms |
15076 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
0 ms |
344 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
0 ms |
344 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
0 ms |
344 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
38 ms |
14536 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |