# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
829933 |
2023-08-18T16:00:29 Z |
NK_ |
Feast (NOI19_feast) |
C++17 |
|
559 ms |
1492 KB |
// Success consists of going from failure to failure without loss of enthusiasm
#include <bits/stdc++.h>
using namespace std;
#define nl '\n'
#define pb push_back
#define mp make_pair
#define f first
#define s second
#define sz(x) int(x.size())
template<class T> using V = vector<T>;
using vi = V<int>;
using ll = long long;
using pi = pair<int, int>;
using vpi = V<pi>;
using vl = V<ll>;
using db = long double;
const int INF = 1e9 + 10;
const db EPS = 1e-3;
const ll INFL = ll(1e16);
using T = pair<db, int>;
int main() {
cin.tie(0)->sync_with_stdio(0);
int N, K; cin >> N >> K;
vi A(N); for(auto& x : A) cin >> x;
V<T> dp(2);
auto check = [&](db lambda) {
dp[0] = {0, 0}; dp[1] = {-db(INFL), 0};
for(int i = 0; i < N; i++) {
V<T> ndp(2); ndp[0] = max(dp[0], dp[1]);
ndp[1] = max(
mp(dp[0].f + A[i] - lambda, dp[0].s + 1),
mp(dp[1].f + A[i], dp[1].s)
);
dp.swap(ndp);
}
return max(dp[0], dp[1]).s >= K;
};
db lo = 0, hi = INFL;
while(lo + EPS < hi) {
db mid = (lo + hi) / 2;
if (check(mid)) lo = mid;
else hi = mid;
}
check(lo);/* cout << lo << endl;*/
cout << round(lo * db(K) + max(dp[0], dp[1]).f) << nl;
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
522 ms |
1364 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
528 ms |
1364 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
559 ms |
1492 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 |
Incorrect |
1 ms |
212 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
522 ms |
1364 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |