#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
constexpr int MAXN = 5e2 + 7;
constexpr ld oo = 1e9;
tuple<ld, ld, int> T[MAXN];
pair<ld, ld> TORG[MAXN];
pair<int, int> prevs[MAXN][MAXN];
ld dp[MAXN][MAXN];
bool blocked[MAXN];
ld sumA;
int n, k;
bool cmp1(tuple<ld, ld, int> a, tuple<ld, ld, int> b){
auto [xa, ya, ia] = a;
auto [xb, yb, ib] = b;
if(ya != yb)
return ya < yb;
return xa < xb;
}
bool cmp2(tuple<ld, ld, int> a, tuple<ld, ld, int> b){
auto [xa, ya, ia] = a;
auto [xb, yb, ib] = b;
if(xa != xb)
return xa < xb;
return ya < yb;
}
ld compute(ld val, ld l){
return (sumA + val)/l;
}
void compute(){
for(int i = 1; i <= n; i++){
dp[i][1] = std::get<1>(T[i]) - std::get<0>(T[i]);
prevs[i][1] = {0, std::get<2>(T[i])};
}
for(int l = 2; l <= k; l++){
for(int i = l; i <= n; i++){
ld actbest = (oo*oo);
for(int j = l-1; j < i; j++){
if(actbest > compute(dp[j][l-1] + dp[i][1], l)){
prevs[i][l] = {j, std::get<2>(T[i])};
dp[i][l] = dp[j][l-1] + dp[i][1];
actbest = compute(dp[i][l], l);
}
}
}
}
}
vector<int> odtworz(int i, int l){
vector<int> out;
int pocz = i;
while(l){
out.push_back(prevs[pocz][l].second);
//cout << "k: " << l << " " << out.back() << "\n";
pocz = prevs[pocz][l--].first;
}
reverse(out.begin(), out.end());
return out;
}
ld solve(){
ld res = oo;
sort(T+1, T+1+n, cmp2);
for(int l = 0; l <= k-1; l++){
for(int i = l; i <= n; i++){
vector<int> odt = odtworz(i, l);
ld act = 0;
for(int z = 1; z <= l; z++){
act += (TORG[odt[z-1]].second/z);
blocked[odt[z-1]] = 1;
}
int it = k - l;
for(int w = 1; w <= n && it > 0; w++){
auto [xa, ya, ia] = T[w];
if(blocked[ia]) continue;
act += (xa / (l+1));
it--;
}
for(auto u : odt)
blocked[u] = 0;
//cout << "k: " << l << " " << act << "\n";
res = min(res, act);
}
}
return res;
}
int main(){
ios_base::sync_with_stdio(0);
cin.tie(0);
cin >> n >> k;
for(int i = 1; i <= n; i++){
ld a, b;
cin >> a >> b;
sumA += a;
if(b == -1) b = 1e9;
TORG[i] = {a, b};
T[i] = {a, b, i};
}
sort(T+1, T+1+n, cmp1);
compute();
cout << fixed << setprecision(9) << solve() << "\n";
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
2396 KB |
Output is correct |
2 |
Correct |
1 ms |
2396 KB |
Output is correct |
3 |
Correct |
1 ms |
2396 KB |
Output is correct |
4 |
Correct |
1 ms |
2392 KB |
Output is correct |
5 |
Correct |
33 ms |
6432 KB |
Output is correct |
6 |
Correct |
88 ms |
6236 KB |
Output is correct |
7 |
Correct |
184 ms |
6420 KB |
Output is correct |
8 |
Correct |
284 ms |
6664 KB |
Output is correct |
9 |
Correct |
349 ms |
6236 KB |
Output is correct |
10 |
Correct |
224 ms |
6480 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
2396 KB |
Output is correct |
2 |
Correct |
1 ms |
2396 KB |
Output is correct |
3 |
Correct |
1 ms |
2396 KB |
Output is correct |
4 |
Correct |
1 ms |
2392 KB |
Output is correct |
5 |
Correct |
33 ms |
6432 KB |
Output is correct |
6 |
Correct |
88 ms |
6236 KB |
Output is correct |
7 |
Correct |
184 ms |
6420 KB |
Output is correct |
8 |
Correct |
284 ms |
6664 KB |
Output is correct |
9 |
Correct |
349 ms |
6236 KB |
Output is correct |
10 |
Correct |
224 ms |
6480 KB |
Output is correct |
11 |
Correct |
1 ms |
2396 KB |
Output is correct |
12 |
Correct |
93 ms |
6440 KB |
Output is correct |
13 |
Correct |
96 ms |
6236 KB |
Output is correct |
14 |
Correct |
97 ms |
6436 KB |
Output is correct |
15 |
Correct |
249 ms |
6416 KB |
Output is correct |
16 |
Correct |
244 ms |
6408 KB |
Output is correct |
17 |
Correct |
265 ms |
6416 KB |
Output is correct |
18 |
Correct |
328 ms |
6420 KB |
Output is correct |
19 |
Correct |
325 ms |
6232 KB |
Output is correct |
20 |
Correct |
344 ms |
6484 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
2392 KB |
Output is correct |
2 |
Correct |
1 ms |
2392 KB |
Output is correct |
3 |
Correct |
1 ms |
2396 KB |
Output is correct |
4 |
Correct |
1 ms |
2396 KB |
Output is correct |
5 |
Correct |
1 ms |
2512 KB |
Output is correct |
6 |
Correct |
1 ms |
2396 KB |
Output is correct |
7 |
Correct |
1 ms |
2396 KB |
Output is correct |
8 |
Correct |
1 ms |
2396 KB |
Output is correct |
9 |
Correct |
1 ms |
2392 KB |
Output is correct |
10 |
Correct |
1 ms |
2396 KB |
Output is correct |
11 |
Incorrect |
1 ms |
2392 KB |
Output isn't correct |
12 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
2392 KB |
Output is correct |
2 |
Correct |
1 ms |
2392 KB |
Output is correct |
3 |
Correct |
1 ms |
2396 KB |
Output is correct |
4 |
Correct |
1 ms |
2396 KB |
Output is correct |
5 |
Correct |
1 ms |
2512 KB |
Output is correct |
6 |
Correct |
1 ms |
2396 KB |
Output is correct |
7 |
Correct |
1 ms |
2396 KB |
Output is correct |
8 |
Correct |
1 ms |
2396 KB |
Output is correct |
9 |
Correct |
1 ms |
2392 KB |
Output is correct |
10 |
Correct |
1 ms |
2396 KB |
Output is correct |
11 |
Incorrect |
1 ms |
2392 KB |
Output isn't correct |
12 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
2392 KB |
Output is correct |
2 |
Correct |
1 ms |
2392 KB |
Output is correct |
3 |
Correct |
1 ms |
2396 KB |
Output is correct |
4 |
Correct |
1 ms |
2396 KB |
Output is correct |
5 |
Correct |
1 ms |
2512 KB |
Output is correct |
6 |
Correct |
1 ms |
2396 KB |
Output is correct |
7 |
Correct |
1 ms |
2396 KB |
Output is correct |
8 |
Correct |
1 ms |
2396 KB |
Output is correct |
9 |
Correct |
1 ms |
2392 KB |
Output is correct |
10 |
Correct |
1 ms |
2396 KB |
Output is correct |
11 |
Incorrect |
1 ms |
2392 KB |
Output isn't correct |
12 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
370 ms |
6416 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
2396 KB |
Output is correct |
2 |
Correct |
1 ms |
2396 KB |
Output is correct |
3 |
Correct |
1 ms |
2396 KB |
Output is correct |
4 |
Correct |
1 ms |
2392 KB |
Output is correct |
5 |
Correct |
33 ms |
6432 KB |
Output is correct |
6 |
Correct |
88 ms |
6236 KB |
Output is correct |
7 |
Correct |
184 ms |
6420 KB |
Output is correct |
8 |
Correct |
284 ms |
6664 KB |
Output is correct |
9 |
Correct |
349 ms |
6236 KB |
Output is correct |
10 |
Correct |
224 ms |
6480 KB |
Output is correct |
11 |
Correct |
1 ms |
2396 KB |
Output is correct |
12 |
Correct |
93 ms |
6440 KB |
Output is correct |
13 |
Correct |
96 ms |
6236 KB |
Output is correct |
14 |
Correct |
97 ms |
6436 KB |
Output is correct |
15 |
Correct |
249 ms |
6416 KB |
Output is correct |
16 |
Correct |
244 ms |
6408 KB |
Output is correct |
17 |
Correct |
265 ms |
6416 KB |
Output is correct |
18 |
Correct |
328 ms |
6420 KB |
Output is correct |
19 |
Correct |
325 ms |
6232 KB |
Output is correct |
20 |
Correct |
344 ms |
6484 KB |
Output is correct |
21 |
Correct |
1 ms |
2392 KB |
Output is correct |
22 |
Correct |
1 ms |
2392 KB |
Output is correct |
23 |
Correct |
1 ms |
2396 KB |
Output is correct |
24 |
Correct |
1 ms |
2396 KB |
Output is correct |
25 |
Correct |
1 ms |
2512 KB |
Output is correct |
26 |
Correct |
1 ms |
2396 KB |
Output is correct |
27 |
Correct |
1 ms |
2396 KB |
Output is correct |
28 |
Correct |
1 ms |
2396 KB |
Output is correct |
29 |
Correct |
1 ms |
2392 KB |
Output is correct |
30 |
Correct |
1 ms |
2396 KB |
Output is correct |
31 |
Incorrect |
1 ms |
2392 KB |
Output isn't correct |
32 |
Halted |
0 ms |
0 KB |
- |