#include "bits/stdc++.h"
using namespace std;
void abc() {cout << endl;}
template <typename T, typename ...U> void abc(T a, U ...b) {
cout << a << ' ', abc(b...);
}
template <typename T> void printv(T l, T r) {
while (l != r) cout << *l << " \n"[++l == r];
}
template <typename A, typename B> istream& operator >> (istream& o, pair<A, B> &a) {
return o >> a.first >> a.second;
}
template <typename A, typename B> ostream& operator << (ostream& o, pair<A, B> a) {
return o << '(' << a.first << ", " << a.second << ')';
}
template <typename T> ostream& operator << (ostream& o, vector<T> a) {
bool is = false;
for (T i : a) {o << (is ? ' ' : '{'), is = true, o << i;}
return o << '}';
}
#ifdef local
#define test(args...) abc("[" + string(#args) + "]", args)
#else
#define test(args...) void(0)
#endif
using ll = long long;
vector<pair<int, int>> v;
int goal, n, k;
long double dp[505][505];
long double solve(int node, int ctcollab) {
if (dp[node][ctcollab] != -1) return dp[node][ctcollab];
int ctnorm = node - ctcollab;
if (ctcollab == goal) {
vector<pair<int, int>> cur;
for (int i = node; i < n; i++) {
cur.emplace_back(v[i]);
}
sort(cur.begin(), cur.end());
long double ct = 0;
for (int i = 0; i < k - node; i++) {
ct += (long double) cur[i].first / (ctcollab + 1);
}
return dp[node][ctcollab] = ct;
}
long double ans = solve(node + 1, ctcollab + 1) + (long double) v[node].second / (ctcollab + 1);
if (ctnorm + ctcollab < k) {
ans = min(ans, solve(node + 1, ctcollab) + (long double) v[node].first / (goal + 1));
}
return dp[node][ctcollab] = ans;
}
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0); cout.tie(0);
// freopen("", "r", stdin);
// freopen("", "w", stdout);
cin >> n >> k;
for (int i = 0; i < n; i++) {
int a, b; cin >> a >> b;
if (b == -1) b = 1e9;
v.emplace_back(a, b);
}
sort(v.begin(), v.end(), [](pair<int, int> a, pair<int, int> b) {
return a.second < b.second;
});
long double ans = 1e18;
for (int i = 0; i < k; i++) {
goal = i;
fill(&dp[0][0], &dp[0][0] + sizeof(dp) / sizeof(dp[0][0]), -1);
long double res = solve(0, 0);
ans = min(ans, res);
}
cout << ans;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
4180 KB |
Output is correct |
2 |
Incorrect |
2 ms |
4308 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
4180 KB |
Output is correct |
2 |
Incorrect |
2 ms |
4308 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
4180 KB |
Output is correct |
2 |
Correct |
3 ms |
4308 KB |
Output is correct |
3 |
Correct |
3 ms |
4308 KB |
Output is correct |
4 |
Correct |
3 ms |
4308 KB |
Output is correct |
5 |
Correct |
6 ms |
4308 KB |
Output is correct |
6 |
Correct |
7 ms |
4296 KB |
Output is correct |
7 |
Incorrect |
5 ms |
4308 KB |
Output isn't correct |
8 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
4180 KB |
Output is correct |
2 |
Correct |
3 ms |
4308 KB |
Output is correct |
3 |
Correct |
3 ms |
4308 KB |
Output is correct |
4 |
Correct |
3 ms |
4308 KB |
Output is correct |
5 |
Correct |
6 ms |
4308 KB |
Output is correct |
6 |
Correct |
7 ms |
4296 KB |
Output is correct |
7 |
Incorrect |
5 ms |
4308 KB |
Output isn't correct |
8 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
4180 KB |
Output is correct |
2 |
Correct |
3 ms |
4308 KB |
Output is correct |
3 |
Correct |
3 ms |
4308 KB |
Output is correct |
4 |
Correct |
3 ms |
4308 KB |
Output is correct |
5 |
Correct |
6 ms |
4308 KB |
Output is correct |
6 |
Correct |
7 ms |
4296 KB |
Output is correct |
7 |
Incorrect |
5 ms |
4308 KB |
Output isn't correct |
8 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
2067 ms |
4372 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
4180 KB |
Output is correct |
2 |
Incorrect |
2 ms |
4308 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |