# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
573574 |
2022-06-06T21:21:58 Z |
danikoynov |
Feast (NOI19_feast) |
C++14 |
|
1000 ms |
5612 KB |
/**
____ ____ ____ ____ ____ ____
||l |||e |||i |||n |||a |||d ||
||__|||__|||__|||__|||__|||__||
|/__\|/__\|/__\|/__\|/__\|/__\|
**/
#include<bits/stdc++.h>
#define endl '\n'
using namespace std;
typedef long long ll;
void speed()
{
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
}
const int maxn = 3e5 + 10;
int n;
ll k, a[maxn], dp[maxn], cnt[maxn], par[maxn];
pair < ll, int > calc(ll cost)
{
for (int i = 1; i <= n; i ++)
{
dp[i] = dp[i - 1];
cnt[i] = cnt[i - 1];
for (int j = 1; j <= i; j ++)
{
ll sum = dp[j - 1] - cost + par[i] - par[j - 1];
if (sum > dp[i])
dp[i] = sum;
if (sum == dp[i])
cnt[i] = max(cnt[i], cnt[j - 1] + 1);
}
}
return {dp[n], cnt[n]};
}
void solve()
{
cin >> n >> k;
if (k > 5)
while(true);
ll cnt = 0;
for (int i = 1; i <= n; i ++)
{
cin >> a[i];
if (a[i] >= 0)
cnt ++;
par[i] = par[i - 1] + a[i];
}
k = min(cnt, k);
ll lf = 0, rf = 1e12;
while(lf <= rf)
{
ll mf = (lf + rf) / 2;
pair < double, int > cur = calc(mf);
if (cur.second >= k)
lf = mf + 1;
else
rf = mf - 1;
}
double p1 = lf - 1, p2 = lf;
pair < ll, int > cur1 = calc(p1), cur2 = calc(p2);
cur1.first = cur1.first + cur1.second * p1;
cur2.first = cur2.first + cur2.second * p2;
double part = 1.0 - (double)(cur1.second - k) / (double)(cur1.second - cur2.second);
double slope = (cur1.first - cur2.first);
double ans = cur2.first + slope * part;
///cout << cur1.second << " " << cur2.second << " " << part << " " << cur1.second - k << " " << k << endl;
if (cur1.second == cur2.second)
{
cout << cur1.first << endl;
return;
}
cout << round(ans) << endl;
}
int main()
{
solve();
return 0;
}
/**
7 1
3 4 -1 2 3 -5 1
*/
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
1082 ms |
212 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
1080 ms |
5488 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
1089 ms |
5612 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
212 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
212 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
212 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
1082 ms |
212 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |