# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
927887 |
2024-02-15T13:44:38 Z |
sleepntsheep |
Feast (NOI19_feast) |
C++17 |
|
1000 ms |
20060 KB |
#include <cstdio>
#include <cmath>
#include <climits>
#include <functional>
#include <numeric>
#include <cstring>
#include <cassert>
#include <string>
#include <deque>
#include <vector>
#include <map>
#include <queue>
#include <algorithm>
#include <iostream>
#include <utility>
using namespace std;
using ll=long long;
#define N 300005
#define ALL(x) x.begin(), x.end()
int n, k, a[N];
long long p[N];
pair<long double, int> dp[N][2];
const long double EPS = 1e-3;
int check(long double lambda)
{
dp[0][1] = make_pair(-1e18, 0);
for (int 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][0].first + a[i] - lambda, dp[i-1][0].second + 1),
make_pair(dp[i-1][1].first + a[i], dp[i-1][1].second));
}
return max(dp[n][0], dp[n][1]).second >= k;
}
int main()
{
cin.tie(0)->sync_with_stdio(0);
cin >> n >> k;
for (int i = 1; i <= n; ++i) cin >> a[i];
ll l = 0, r = 1e18;
while (l <= r)
{
ll y = (l+r)/2;
if (check(y)) l = y;
else r = y;
}
check(l);
cout << (long long)round(k * l + max(dp[n][0], dp[n][1]).first);
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
1049 ms |
20060 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
1020 ms |
20056 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
1041 ms |
20048 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
1044 ms |
344 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
1044 ms |
344 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
1044 ms |
344 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
1049 ms |
20060 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |