# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
1017348 |
2024-07-09T07:31:41 Z |
_shr104 |
Feast (NOI19_feast) |
C++14 |
|
101 ms |
13936 KB |
#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;
ll opt = lmb(m).se;
if (opt >= k)
{
l = m+1;
ans = m;
}
else r = m-1;
}
cout << max(lmb(ans).fi + ans*k,0LL);
}
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();
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
69 ms |
11868 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
65 ms |
12124 KB |
Output is correct |
2 |
Correct |
64 ms |
12044 KB |
Output is correct |
3 |
Correct |
70 ms |
12124 KB |
Output is correct |
4 |
Incorrect |
81 ms |
12124 KB |
Output isn't correct |
5 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
99 ms |
12148 KB |
Output is correct |
2 |
Correct |
99 ms |
13908 KB |
Output is correct |
3 |
Correct |
98 ms |
13936 KB |
Output is correct |
4 |
Correct |
101 ms |
13900 KB |
Output is correct |
5 |
Correct |
99 ms |
13908 KB |
Output is correct |
6 |
Correct |
100 ms |
13904 KB |
Output is correct |
7 |
Correct |
99 ms |
13712 KB |
Output is correct |
8 |
Correct |
95 ms |
13904 KB |
Output is correct |
9 |
Correct |
101 ms |
13904 KB |
Output is correct |
10 |
Correct |
101 ms |
13904 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
19 ms |
9816 KB |
Output is correct |
2 |
Incorrect |
19 ms |
9820 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
19 ms |
9816 KB |
Output is correct |
2 |
Incorrect |
19 ms |
9820 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
19 ms |
9816 KB |
Output is correct |
2 |
Incorrect |
19 ms |
9820 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
69 ms |
11868 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |